JSP课程设计留言簿课程设计.docx
JSP课程设计留言簿课程设计 JSP留言簿课程设计 一 需求分析 随着互联网的迅猛的发展,网站给我们带来不少的便利,于此同时,留言簿基本是每个网站必有的功能,为用户之间的交流提供的很好的平台。通过仔细的分析和规划,本留言簿有如下功能:用户注册,登录,签写留言,留言查看等几项普通功能,是一个较为简单的留言簿程序。 二 分析和设计 在用户发表留言后,将显示该用户的用户名、性别、留言内容等内容。另外还能在页面中显示当前的系统的时间和访问权限。 三 各页面功能实现说明 1 登录界面 代码如下: <formaction="Tests.jsp"> <h2>登陆界面</h2> <%pagecontentType="text/html;charset=gb2312"%> 用户名:<inputtype="text"name="userName"> <br> <br> <inputtype="submit"value="确定"> <inputtype="reset"value="取消"> </form> 密 码:<inputtype="password"name="userPass"> 2.留言界面 输入正确用户名 admin及密码000 后进入留言界面。 留言界面代码如下: <%pagelanguage="java"import="java.util.*"pageEncoding="gb2312"%> <% String path = request.getContextPath; String basePath = request.getScheme+":/"+request.getServerName+":"+request.getServerPort+path+"/" %> <!DOCTYPEHTMLPUBLIC"-/W3C/DTD HTML 4.01 Transitional/EN"> <html> <head> <basehref="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <body> <formaction="doword.jsp"methed="post"> <tablealign=""> <tr> <td>留言者</td> <td><inputtype="text"name="author"size="20"></td> </tr> <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="This is my page"> <!- <link rel="stylesheet" type="text/css" href="styles.css"> -> </head> <trheight="30"> <td>留言标题</td> <td><inputtype="text"name="title"size="35"></td> </tr> <tr> <td>留言内容</td> <td><textareaname="content"rows="8"cols="34"></textarea></td> </tr> <tralign="center"> <tdcolspan="2"><inputtype="submit"value="提交"> <inputtype="reset"value="重置"></td> </tr> </table> </form> </body> </html> 3.封装与判断用户名、密码是否正确的javabean-Match.java处理包代码 packagecom.yxq.toolbean; publicclass Match / private String userName; private String userPass; publicStringgetUserName publicvoidsetUserName(String userName) public String getUserPass publicvoidsetUserPass(String userPass) publicboolean Test(String userName,StringuserPass) if(userName.equals("admin")&&userPass.equals("000") returntrue; returnfalse; this.userPass = userPass; returnuserPass; this.userName = userName; returnuserName; else 4.成功登陆的succes.jsp界面 <%pagelanguage="java"import="java.util.*"pageEncoding="gb2312"%> <% String path = request.getContextPath; String basePath = request.getScheme+":/"+request.getServerName+":"+request.getServerPort+path+"/" %> <!DOCTYPEHTMLPUBLIC"-/W3C/DTD HTML 4.01 Transitional/EN"> <html> <head> <basehref="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <body> <formaction="doword.jsp"methed="post"> <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="This is my page"> <!- <link rel="stylesheet" type="text/css" href="styles.css"> -> </head> <tablealign=""> <tr> <td>留言者</td> <td><inputtype="text"name="author"size="20"></td> </tr> <trheight="30"> <td>留言标题</td> <td><inputtype="text"name="title"size="35"></td> </tr> <tr> <td>留言内容</td> <td><textareaname="content"rows="8"cols="34"></textarea></td> </tr> <tralign="center"> <tdcolspan="2"><inputtype="submit"value="提交"> <inputtype="reset"value="重置"></td> </tr> </table> </form> </body> </html> 5.fault.jsp错误提示界面 如果输入错误用户名或密码则进入提示fault.jsp错误提示界面 代码如下: <%pagecontentType="text/html;charset=gb2312"%> <html> <head> <title>登陆 </title> </head> <body> <h2>登陆界面</h2> <hr> 登录失败!请<ahref="index.jsp">重新登陆</a> </body> </html> 6. 显示留言信息的show.jsp界面 显示留言信息的show.jsp界面,在该页面中将获取在doword,jsp页面中存储的javabean,然后将其中的getXxx方法获取留言信息。如果直接将通过getXxx方法获取的信息输出到页面中,就会出现乱码,所以还需要调用mytools工具javabean中的tochinese方法进行转码操作。 show.jsp界面截图及代码如下 <%pagelanguage="java"import="java.util.*"contentType="text/html; charset=gb2312"%> <%pageimport="com.yxq.toolbean.MyTools" %> <jsp:useBeanid="myWord"class="com.yxq.valuebean.WordSingle"scope="request"/> <% String path = request.getContextPath; String basePath = request.getScheme+":/"+request.getServerName+":"+request.getServerPort+path+"/" %> <!DOCTYPEHTMLPUBLIC"-/W3C/DTD HTML 4.01 Transitional/EN"> <html> <head> <basehref="<%=basePath%>"> <title>My JSP 'show.jsp' starting page</title> </head> <body> <tableborder="1"height="200px"riles="rows"> <tr> <tdalign="center">留言者:</td> <td><%=MyTools.toChinese(myWord.getAuthor) %></td> </tr> <trheight="30"> <tdalign="center">留言标题:</td> <td><%=MyTools.toChinese(myWord.getTitle) %></td> </tr> <tr> <tdalign="center">留言内容:</td> <td><textarearows="8"cols="34"readonly> <%=MyTools.toChinese(myWord.getContent) %> </textarea> </td> </tr> <tr> <tdcolspan="2"align="center"><ahref="success.jsp">继续留言</a></td> </tr> </table> </body> </html> <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="This is my page"> <!- <link rel="stylesheet" type="text/css" href="styles.css"> -> 7.解决中文乱码的转码操作的工具javabean-mytools.在该bean中创建一个方法,该方法存在一个String型参数,在方法体内编码实现对该数进行转码的操作。MyTools类的代码如下: packagecom.yxq.toolbean; importjava.io.UnsupportedEncodingException; publicclassMyTools publicstatic String toChinese(String str) if(str=null) returnstr; str="" str=new String(str.getBytes("ISO-8859-1"),"gb2312"); str="" e.printStackTrace; try catch(UnsupportedEncodingException e) 8.用来封装表单数据的值JavaBean-Wordsingle。该bean存在auther、title、congtent三个属性,分别用来存储index页面中的留言者、留言标题、和留言内容字段。代码如下: packagecom.yxq.valuebean; publicclassWordSingle private String author; private String title; private String content; public String getAuthor publicvoidsetAuthor(String author) public String getTitle publicvoidsetTitle(String title) this.title = title; returntitle; this.author = author; returnauthor; public String getContent publicvoidsetContent(String content) this.content = content; returncontent; 9.表单处理页doword.jsp,该页面主要用来接受表单数据,然后将请求转发到show.jsp页面来显示用户输入的信息。Doword.jsp页面的代码如下 %<%page language="java" contentType="text/html;charset=gb2312"%> uest"> <jsp:setPropertyname="myWord"property="*"/> <jsp:forwardpage="show.jsp"/> </jsp:useBean> import="java.util.*" <jsp:useBeanid="myWord"class="com.yxq.valuebean.WordSingle"scope="req