JavaEE实验3报告-昆明理工大学_第1页
JavaEE实验3报告-昆明理工大学_第2页
JavaEE实验3报告-昆明理工大学_第3页
JavaEE实验3报告-昆明理工大学_第4页
JavaEE实验3报告-昆明理工大学_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

昆明理工大学信息工程与自动化学院学生实验报告(2012—2013学年第一学期)课程名称:JAVAEE技术开课实验室:信自楼4442012年12月19日年级、专业、班计科10级学号姓名成绩实验项目名称实验三Jsp+Javabean+JSTL综合设计指导教师杨云飞教师评语教师签名:年月日一、实验目的通过上机,熟练掌握JSP编程、JavaBean的应用以及EL和JSTL的应用。二、内容及要求1、上机内容:编写两个JavaBean,实现值类和业务类。编写servlet实现控制的功能;编写top.jsp、left.jsp、bottom.jsp、employeemain.jsp,实现页面的组装。在left.jsp增加登录部分,若登录成功后在同样的位置显示:欢迎您和用户号。在top.jsp中增加两个链接,实现投票和管理投票中心,其中管理投票中心只有在登录成功后方显示。。三、步骤及具体实施1、简要描述程序的开发流程、文件部署截图、及各种配置;2、程序代码packagechapter10.dao;importjava.util.*;importjava.sql.*;importchapter10.value.EmployeeValue;publicclassEmployeeBusiness{ publicListgetList()throwsException { ListempList=newArrayList(); Stringsql="select*fromuserinfo"; Connectioncn=null; try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); cn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=javaee","root","123"); Statementstmt=cn.createStatement(); //PreparedStatementps=cn.prepareStatement(sql); ResultSetrs=stmt.executeQuery(sql); while(rs.next()) { EmployeeValueev=newEmployeeValue(); ev.setUserId(rs.getString("userid")); ev.setPassWord(rs.getString("password")); ev.setName(rs.getString("name")); ev.setAge(rs.getInt("age")); empList.add(ev); } rs.close(); stmt.close(); } catch(Exceptione) { thrownewException("取得员工列表错误:"+e.getMessage()); } finally { cn.close(); } returnempList; }}importjavax.servlet.Filter;importjavax.servlet.FilterChain;importjavax.servlet.FilterConfig;importjavax.servlet.ServletException;importjavax.servlet.ServletRequest;importjavax.servlet.ServletResponse;importjavax.servlet.http.HttpServletRequestWrapper;importjavax.servlet.http.*;//请求数据字符编码处理过滤器publicclassCharEncodingFilterimplementsFilter{ privateFilterConfigconfig=null; privateStringcontentType=null; privateStringcode=null; //初始化方法,在过滤器对象创建后被调用 publicvoidinit(FilterConfigconfig)throwsServletException { this.config=config; //取得Filter初始化参数 //contentType=config.getInitParameter("contentType"); code=config.getInitParameter("encoding"); System.out.println("init..."); } //过滤方法 publicvoiddoFilter(ServletRequestreq,ServletResponseres, FilterChainchain)throwsIOException,ServletException { //转换为HTTP请求对象 HttpServletRequestrequest=(HttpServletRequest)req; //request.setAttribute("infoType","image/jpeg"); request.setCharacterEncoding(code);//设置字符编码集 res.setCharacterEncoding(code);//设置字符编码集 System.out.println("filting..."); //继续下个过滤器 chain.doFilter(req,res); } //销毁方法,在过滤器销毁前被调用 publicvoiddestroy() { System.out.println("destroy..."); }}<%@pagelanguage="java"import="java.util.*"pageEncoding="GBK"%><%@tagliburi="/jsp/jstl/core"prefix="c"%><%@tagliburi="/jsp/jstl/fmt"prefix="fmt"%><%@tagliburi="/jsp/jstl/sql"prefix="sql"%><%@tagliburi="/jsp/jstl/xml"prefix="x"%><%@tagliburi="/jsp/jstl/functions"prefix="fn"%><%Stringd_id=(String)(request.getParameter("id"));System.out.println("d_id="+d_id);%><sql:setDataSourcedriver="com.mysql.jdbc.Driver"url="jdbc:mysql://localhost/cityoa"user="root"password="abc123"var="infoData"scope="request"/><sql:updatesql="updateuserinfo1setTYPE=?WhereUSERID=?"dataSource="${infoData}"var="result"scope="request"><sql:paramvalue="black"/><sql:paramvalue="<%=d_id%>"/></sql:update><jsp:forwardpage="admin.jsp"/>Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><jsp:useBeanid="now"class="java.util.Date"></jsp:useBean><% request.setCharacterEncoding("gb2312"); HttpSessionsession1=request.getSession(); //取得会话对象中保存的验证码,由验证码生成Servlet存入 Stringuserid=(String)session1.getAttribute("userid"); Stringnote1=request.getParameter("note1"); %><sql:setDataSourcedriver="com.mysql.jdbc.Driver"url="jdbc:mysql://localhost/cityoa"user="root"password="abc123"var="infoData"scope="request"/><sql:updatesql="insertintonotes(id,note,dates)values(?,?,?)"dataSource="${infoData}"var="result"scope="request"> <sql:paramvalue="${userid}"/><sql:paramvalue="<%=note1%>"/><sql:paramvalue="${now}"/></sql:update><jsp:forwardpage="luntan.jsp"/><%@pagecontentType="text/html;charset=GBK"%><%@pagelanguage="java"import="java.sql.*"%><jsp:useBeanid="connDbBean"scope="page"class="javaee.ch04.VoteConn"/><%request.setCharacterEncoding("gb2312");Stringuserid=request.getParameter("userid");Stringname=request.getParameter("name");//Stringpassword=request.getParameter("password"); //Stringrepassword=request.getParameter("repassword"); //Stringusername=request.getParameter("name"); //Filepathname=newFile("F:/apache-tomcat-7.0.23/webapps/04/20.jpg"); //FileInputStreamfilename=newFileInputStream(pathname); //Stringphoto=BinaryStream(//filename,(int)name.length());Stringsql="insertintouserinfo1(USERID,PASSWORD,NAME,SEX,ADDRESS,TEXT,PATH)";sql=sql+"values('"+userid+"','"+userid+"','"+name+"',"+"'man','云南','mynameisben','')";System.out.println("sql:"+sql); connDbBean.executeUpdate(sql);%><jsp:forwardpage="admin.jsp"/><%@pagecontentType="text/html;charset=GBK"%><%@pagelanguage="java"import="java.sql.*"%><jsp:useBeanid="connDbBean"scope="page"class="javaee.ch04.VoteConn"/><%request.setCharacterEncoding("gb2312");Stringuserid=request.getParameter("userid");Stringname=request.getParameter("name");//Stringpassword=request.getParameter("password"); //Stringrepassword=request.getParameter("repassword"); //Stringusername=request.getParameter("name"); //Filepathname=newFile("F:/apache-tomcat-7.0.23/webapps/04/20.jpg"); //FileInputStreamfilename=newFileInputStream(pathname); //Stringphoto=BinaryStream(//filename,(int)name.length());Stringsql="insertintouserinfo1(USERID,PASSWORD,NAME,SEX,ADDRESS,TEXT,PATH)";sql=sql+"values('"+userid+"','"+userid+"','"+name+"',"+"'man','云南','mynameisben','')";System.out.println("sql:"+sql); connDbBean.executeUpdate(sql);%><jsp:forwardpage="admin.jsp"/><%@pagecontentType="text/html;charset=GBK"%><%@pagelanguage="java"import="java.sql.*"%><jsp:useBeanid="connDbBean"scope="page"class="javaee.ch04.VoteConn"/><%request.setCharacterEncoding("gb2312");Stringnn=request.getParameter("note");if(nn!=null&&nn.length()>0){ ResultSettmpRs=connDbBean.executeQuery("selectmax(id)Asmaxidfromvote");tmpRs.next();intmax_id=tmpRs.getInt("maxid")+1;tmpRs.close();Stringsql="insertintovotevalues("+max_id+",'"; sql+=nn+"',0);"; connDbBean.executeUpdate(sql);}x="c"%><jsp:useBeanid="connDbBean"scope="page"class="javaee.ch04.VoteConn"/><html><bodybgcolor="#FFFFFF"><%@includefile="/gl_top.jsp"%><p><fontcolor="#990000"size="+2"><u>同学信息维护中心</u></font></p><% ResultSettempRs=connDbBean.executeQuery("SELECTUSERID,NAME,TYPEFROMuserinfo1");%><tablewidth="80%"border="0"cellspacing="1"cellpadding="2"><tr><tdwidth="10%"class="text1"bgcolor="#99CCFF"><divalign="center">用户ID</div></td><tdwidth="40%"class="text1"bgcolor="#99CCFF"><divalign="center">姓名</div></td><tdwidth="20%"class="text1"bgcolor="#99CCFF"><divalign="center">类型</div></td><tdwidth="10%"class="text1"bgcolor="#99CCFF"><divalign="center">删除</div></td><tdwidth="20%"class="text1"bgcolor="#99CCFF"><divalign="center">操作</div></td></tr><%inti=1; i=i+1;}s="text1"colspan="2"> </td></tr><tr><tdclass="text1"colspan="3"bgcolor="#99CCFF">增加用户</td></tr><tr><tdclass="text1"colspan="3"><formmethod="post"action="adduser_gl.jsp"><p>账号:<inputtype="text"name="userid"size="50"maxlength="50"></p><p>用户名:<inputtype="text"name="name"size="50"maxlength="50"></p><p><inputtype="submit"name="Submit"value="提交"><inputtype="reset"name="Submit2"value="重置">Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><jsp:useBeanid="connDbBean"scope="page"class="javaee.ch04.VoteConn"/><%Stringd_id=request.getParameter("id");if(d_id!=null&&d_id.length()>0){connDbBean.executeUpdate("updateuserinfo1setTYPE=nullWhereUSERID="+d_id);}ngd_id=(String)(request.getParameter("id"));System.out.println("d_id="+d_id);%><sql:setDataSourcedriver="com.mysql.jdbc.Driver"url="jdbc:mysql://localhost/cityoa"user="root"password="abc123"var="infoData"scope="request"/><sql:updatesql="DELETEFROMnotesWhereid=?"dataSource="${infoData}"ngd_id=(String)(request.getParameter("id"));System.out.println("d_id="+d_id);%><sql:setDataSourcedriver="com.mysql.jdbc.Driver"url="jdbc:mysql://localhost/cityoa"user="root"password="abc123"ringd_id=request.getParameter("id");//if(d_id!=null&&d_id.length()>0){System.out.println("要删除的id为:"+request.getParameter("id"));connDbBean.executeUpdate("DELETEFROMuserinfo1WhereUSERID="+d_id);//}%><jsp:forwardpage="admin.jsp"/><%@pagelanguage="java"import="java.sql.*"%><jsp:useBeanid="connDbBean"scope="page"class="javaee.ch04.VoteConn"/><%Stringd_id=request.getParameter("id");if(d_id!=null&&d_id.length()>0){connDbBean.executeUpdate("DELETEFROMVOTEWhereid="+d_id);}tot_num=0;inttmp_num=0;//获取总票数ResultSettmpRs=connDbBean.executeQuery("selectsum(c_num)Astotalnumfromvote");tmpRs.next();tot_num=tmpRs.getInt("totalnum");tmpRs.close();ResultSetrs=connDbBean.executeQuery("select*fromvote");inti=1;while(rs.next()){%> <% tmp_num=rs.getInt("c_num"); %> <tdvalign="bottom"align="center">投票率:<%=Math.floor(tmp_num*100/tot_num)%></br> <imgsrc="back.gif"width="10"height="<%=Math.floor(tmp_num*200/tot_num)%>"></br> <hr> 选项<%=i%>:<%=rs.getString("note")%> </td><%i++;}%></tr></table><ahref="main.jsp">返回</a><%rs.close();%></BODY></HTML><%@pagelanguage="java"import="java.util.*"pageEncoding="GBK"%><divstyle="margin:10px10px20px30px;width:1024px;height:222px;background:url(head.jpg)"><divstyle="margin:192px0px0px;width:1024px;height:30px;"><tablewidth="100%"height="100%"border="0"cellspacing="0"cellpadding="0"><trvalign="bottom"align="center"><tdwidth="300"valign="middle"align="center"><fontcolor="#0000FF"face="微软雅黑"size=5px><ahref="guanlimain.jsp">首页</a></font></td><tdwidth="300"valign="middle"align="center"><fontcolor="#00FF00"face="微软雅黑"size=5px><ahref="admin.jsp">学生信息管理</a></font></td><tdwidth="300"valign="middle"align="center"><fontcolor="#CC0000"face="微软雅黑"size=5px><ahref="glnote.jsp">班级论坛管理</a></font></td><tdwidth="300"valign="middle"align="center"><fontcolor=#174cacface="微软雅黑"size=5px><ahref="vote_gl.jsp">班委选举管理</a></font></td><tdwidth="300"valign="middle"align="center"></td><tdwidth="200"valign="middle"align="center"><ahref="Logout"target=_top>注销</a></td></tr></table></div></div><title>班级论坛</title> <metahttp-equiv="pragma"content="no-cache"> <metahttp-equiv="cache-control"content="no-cache"> <metahttp-equiv="expires"content="0"> <metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"> <metahttp-equiv="description"content="Thisismypage"></head><body><%@includefile="/gl_top.jsp"%><% HttpSessionsession1=request.getSession(); //取得会话对象中保存的验证码,由验证码生成Servlet存入 Stringuserid=(String)session1.getAttribute("userid"); System.out.println("userid:"+userid); %><%@tagliburi="/jsp/jstl/core"prefix="c"%><p>欢迎来到班级论坛</p><sql:setDataSourcedriver="com.mysql.jdbc.Driver"url="jdbc:mysql://localhost/cityoa"user="root"password="abc123"var="noteData"scope="request"/><sql:querysql="select*fromnotes"dataSource="${noteData}"var="notelist"scope="request"><%System.out.println("userid1:"+userid);%></sql:query><hr/> <c:forEachvar="row"items="${notelist.rows}"> <table> <tr> ${row.id}:<br> <td><divstyle="border:solid1pxblack;"><p>${row.note}</p> </div> 发表时间:<fmt:formatDatevalue="${row.dates}"type="both" pattern="yy年MM月dd日"/> <br> </td> <td><ahref="delnote_gl.jsp?id=${row.id}">删除</a></td> </tr> </table> </c:forEach></body></html><%@pagelanguage="java"import="java.util.*"pageEncoding="GBK"%><%@tagliburi="/jsp/jstl/core"prefix="c"%><%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><basehref="<%=basePath%>"><title>MyJSP'grxx.jsp'startingpage</title><divstyle="margin:10px008px;width:100%;"><h1>修改个人信息</h1><hr/><p></p><ahref="mylist.jsp">查询个人信息</a><br/><ahref="xuigaimm.jsp">修改密码</a><br/><ahref="xuigaixx.jsp">修改信息</a></div></td><td><divstyle="margin:10px008px;width:100%;"></div></td></tr></table></body></html><%@pagelanguage="java"import="java.util.*"pageEncoding="GBK"%><%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><%@tagliburi="/jsp/jstl/core"prefix="c"%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><title>班级网站</title> <metahttp-equiv="pragma"content="no-cache"> <metahttp-equiv="cache-control"content="no-cache"> <metahttp-equiv="expires"content="0"> <metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"> <metahttp-equiv="description"content="Thisismypage"> </head><body><%@includefile="/gl_top.jsp"%><tablewidth="100%"border="0"><tr><td><divstyle="margin:10px008px;width:100%;"><%@pagecontentType="text/html;charset=GBK"%><%@pagelanguage="java"import="java.sql.*"%><%@tagliburi="/jsp/jstl/core"prefix="c"%><jsp:useBeanid="connDbBean"scope="application"class="javaee.ch04.VoteConn"/><head> <title>班委候选名单</title></head><%ResultSetrs;rs=connDbBean.executeQuery("select*fromvote");%><bodybgcolor="#FFFFFF"><%@includefile="/top.jsp"%><center><h2><fontcolor="#0000ff">请您投票:</font></h2><formaction="vote.jsp"method="post"><Tableborder="1"bgcolor="#00FFFF"><%while(rs.next()){%><TR><TD><inputtype="radio"name="type"value=<%=rs.getString("id")%>><ahref="mylist_vote.jsp?username=<%=rs.getString("note")%>"><%=rs.getString("note")%></a></TD></TR> <%} rs.close(); %><TRalign="center"><TD><Inputtype="submit"value="投票"></TD></TR><TR><TD><Ahref="details.jsp">查看投票</A></TD></TR></Table></form></center></body></html><%@pagelanguage="java"import="java.util.*"pageEncoding="gb2312"%><%@tagliburi="/jsp/jstl/core"prefix="c"%><%@tagliburi="/jsp/jstl/fmt"prefix="fmt"%><%@tagliburi="/jsp/jstl/sql"prefix="sql"%><%@tagliburi="/jsp/jstl/xml"prefix="x"%><%@tagliburi="/jsp/jstl/functions"prefix="fn"%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><title>班级论坛</title> <metahttp-equiv="pragma"content="no-cache"> <metahttp-equiv="cache-control"content="no-cache"> <metahttp-equiv="expires"content="0"> <metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"> <metahttp-equiv="description"content="Thisismypage"></head><body><% HttpSessionsession1=request.getSession(); //取得会话对象中保存的验证码,由验证码生成Servlet存入 Stringuserid=(String)session1.getAttribute("userid"); System.out.println("userid:"+userid); %><%@includefile="/top.jsp"%><p>欢迎来到班级论坛</p><sql:setDataSourcedriver="com.mysql.jdbc.Driver"url="jdbc:mysql://localhost/cityoa"user="root"password="abc123"var="noteData"scope="request"/><sql:querysql="selectnote,dates,NAMEfromnotes,userinfo1whereidlikeUSERID"dataSource="${noteData}"var="notelist"scope="request"><%System.out.println("userid1:"+userid);%></sql:query><hr/> <c:forEachvar="row"items="${notelist.rows}"> ${row.NAME}:<br><divstyle="border:solid1pxblack;"><p>${row.note}</p> </div> 发表时间:<fmt:formatDatevalue="${row.dates}"type="both" pattern="yy年MM月dd日"/> <br> </c:forEach><hr/><p>我要发表:</p> <formmethod="post"action="addnote.jsp">rs=connDbBean.executeQuery("select*fromvote");%><h2><fontcolor="#0000ff">请您投票:</font></h2><formaction="vote.jsp"method="post"><Tableborder="1"bgcolor="#00FFFF"><%while(rs.next()){%><TR><TD><inputtype="radio"name="type"value=<%=rs.getString("id")%>><ahref="mylist_vote.jsp?username=<%=rs.getString("not

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论