广州大学学生实验报告开课学院及实验室:计算机科学与工程电子楼4182018/6/12学院计算机科学与教育软件学院年级/专业/班网工152姓名学号实验课程名称Web应用技术成绩实验项目名称实验四:WEB综合设计指导老师陈文彬一、实验目的WEB综合设计二、实验设备Tomcatwindows10eclipse三、实验内容自选主题设计并建立一个网站(如个人网站,花店网站,书店网站,网上论坛等)。实验成绩根据综合设计中包含所学的web技术:静态HTML,CSS,JavaScript,JSP,JavaBean,Servlet技术的多少给定。四、实验程序实现一个简单的购物车程序1.注册页面reg.jsp%@pagelanguage=javapageEncoding=utf-8%!DOCTYPEhtmlhtmlheadmetahttp-equiv=Content-Typecontent=text/html;charset=utf-8title注册页面/titlelinkhref=styles/index.cssrel=stylesheet/headbody!--文件引入的两种方式--%--%@includefile=include/header.inc.html%--%jsp:includepage=include/header.inc.html/jsp:includepclass=welcome欢迎进入购物车注册界面/pformaction=doreg.jspmethod=postdivh2用户名:/h2inputclass=inputtype=textname=usernameplaceholder=请输入用户名/divdivh2密码:/h2inputclass=inputtype=passwordname=pwdplaceholder=请输入您的密码/divdivinputclass=input1type=submitvalue=注册inputclass=input1type=resetvalue=重置/divh3已有账号,直接ahref=index.jsp登陆/a/h3/form%@includefile=include/footer.inc.html%/body/html2.需要写一个数据库来存储用户信息,表名为·user·;(创建表的语句不写)2.1还需要一个表来存储商品信息goods表createtable`goods1`(idintnotnullauto_incrementprimarykey,goods_namevarchar(20),goodspicvarchar(30),goods_pridouble(10),goods_name_envarchar(20))engine=InnoDBdefaultcharset=utf8;3.用户注册的信息以post的方式提交给doreg.jsp来处理,注册成功即跳转商品页面goods.jsp%@pageimport=java.sql.*%%@pagelanguage=javapageEncoding=GB18030%%try{Class.forName(com.mysql.jdbc.Driver);//加载数据库驱动,注册到驱动管理器Stringurl=jdbc:mysql://127.0.0.1:3301/shopcar;//数据库连接字符串Stringusename=root;Stringpassword=123456;Connectionconn=DriverManager.getConnection(url,usename,password);//创建Connection连接if(conn!=null){System.out.println(数据库链接成功!);//conn.close();//关闭数据库连接Stringinsert_db=INSERTINTO`user`(uesrname,password)values(?,?);//插入操作PreparedStatementstatement=(PreparedStatement)conn.prepareStatement(insert_db);statement.setString(1,request.getParameter(username));statement.setString(2,request.getParameter(pwd));statement.executeUpdate();session.setAttribute(userName,request.getParameter(username));//给当前注册用户开启会话out.println(插入成功);out.println(页面在3秒钟内自动跳转);out.println(ahref=\goods.jsp\点击请进入购物页面/a);}else{out.println(数据库连接失败);//输出错误信息}}catch(ClassNotFoundExceptione){e.printStackTrace();}catch(SQLExceptione){e.printStackTrace();}%!DOCTYPEhtmlPUBLIC-//W3C//DTDHTML4.01Transitional//EN=Content-Typecontent=text/html;charset=utf-8metahttp-equiv=refreshcontent=2;url=goods.jsptitle注册页面/title/headbody/body/html4.已有账户的用户直接登陆进行,index.jsp%@pagelanguage=javaimport=java.util.*contentType=text/html;charset=UTF-8pageEncoding=UTF-8%%Cookie[]cookies=request.getCookies();Stringuname=;Stringupwd=;Stringutrue=;if(cookies!=null){for(inti=0;icookies.length;i++){Cookiecookie=cookies[i];if(cookie.getName().equals(rname)){uname=cookie.getValue();}elseif(cookie.getName().equals(rpwd)){upwd=cookie.getValue();}elseif(cookie.getName().equals(rtrue)){utrue=cookie.getValue();}}}%!DOCTYPEhtmlhtmlheadmetahttp-equiv=X-UA-Compatiblecontent=IE=edge,chrome=1metahttp-equiv=Content-Typecontent=text/html;charset=utf-8title欢迎进入购物车/titlelinkhref=styles/index.cssrel=stylesheet/headbody%--%@includefile=include/header.inc.html%--%jsp:includepage=include/header.inc.html/jsp:includepclass=welcome欢迎进入购物车登陆界面/pformaction=show.jspdivh2用户名:/h2inputclass=inputtype=textname=usernamevalue=%=uname%placeholder=请输入用户名/divdivh2密码:/h2inputclass=inputtype=passwordname=pwdvalue=%=upwd%placeholder=请输入您的密码/divdivinputtype=checkboxname=remembervalue=trueinputclass=input1type=submitvalue=登陆inputclass=input1type=resetvalue=重置/divdivp还没有注册,请先注册/pahref=reg.jsp注册/a/div/form%@includefile=include/footer.inc.html%/body/html5.检测登陆结果用show.jsp来验证。%@pageimport=java.sql.*%%@pagelanguage=javacontentType=text/html;charset=GB18030pageEncoding=GB18030%!DOCTYPEhtmlPUBLIC-//W3C//DTDHTML4.01Transitional//EN=Content-Typecontent=text/html;charset=GB18030titleInserttitlehere/title/headbody%Stringusername=request.getParameter(username);Stringpassword=request.getParameter(pwd);Stringremember=request.getParameter(remember);if(username==null)username=;if(password==null)password=;if(remember==null)remember=false;Stringdriver=com.mysql.jdbc.Driver;Stringurl=jdbc:mysql://127.0.0.1:3301/shopcar;Stringuser=root;Stringpassword_db=123456;try{Class.forName(driver);//加载驱动Connectionconn=DriverManager.getConnection(url,user,password_db);//连接URL为jdbc:mysql://服务器地址/数据库名,后面的2个参数分别是登陆用户名和密码System.out.println(SuccessconnectMysqlserver!);//statement用来执行SQL语句Statementstmt=conn.createStatement();//结果集ResultSetrs=stmt.executeQuery(select*from`user`);//student为你表的名称while(rs.next()){Stringname=rs.getString(uesrname);Stringpwd=rs.getString(password);/*out.println(rs.getString(uesrname));out.println(rs.getString(password)+br);*/if(username!=null&&username.equals(name)&&pas