站长资源网络编程

关于JSP的一点疑问小结

整理:jimmy2026/4/15浏览2
简介希望谁能帮我看一看问题出在哪?谢谢! register.html部分: 复制代码 代码如下: register.html</titl</div> <div class="news_infos"><div id="MyContent">希望谁能帮我看一看问题出在哪?谢谢! <BR>register.html部分: <BR><U>复制代码</U> 代码如下:<BR><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <BR><html> <BR><head> <BR><title>register.html</title> <BR><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <BR><meta http-equiv="description" content="this is my page"> <BR><meta http-equiv="content-type" content="text/html; charset=UTF-8"> <BR><!--<link rel="stylesheet" type="text/css" href="./styles.css">--> <BR></head> <BR><body> <BR><br> <BR><form action="register.jsp" method = "Post" name = "frm"> <BR>用户名:<input type = "text" name = "in_username"><br> <BR>密码:<input type = "password" name = "in_password"><br> <BR><input type = "submit" name = "submit" value = "提交"> <BR></form> <BR></body> <BR></html> <BR><BR>register.jsp部分: <BR><U>复制代码</U> 代码如下:<BR><%@ page language="java" import = java.util.* pageEncoding="ISO-8859-1"%> <BR><% <BR>String path = request.getContextPath(); <BR>String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; <BR>%> <BR><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <BR><html> <BR><head> <BR><base href="<%=basePath%>"> <BR><title>My JSP 'register.jsp' starting page</title> <BR><meta http-equiv="pragma" content="no-cache"> <BR><meta http-equiv="cache-control" content="no-cache"> <BR><meta http-equiv="expires" content="0"> <BR><meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <BR><meta http-equiv="description" content="This is my page"> <BR><meta http-equiv = "content-type" content = "text/html;charset = gb2312"> <BR><!-- <BR><link rel="stylesheet" type="text/css" href="styles.css"> <BR>--> <BR></head> <BR><body> <BR><br> <BR><%! boolean isnotlogin = false;%> <BR><% <BR>String username = request.getParameter("username"); <BR>String password = request.getParameter("password"); <BR>if(username == null || password == null) <BR>{ <BR>response.sendRedirect("error.jsp"); <BR>return; <BR>} <BR>%> <BR><jsp:useBean id="person" scope = "page" class = "mypack.register"> <BR><jsp:setProperty name = "person" property = "username" param = "username"/> <BR><jsp:setProperty name = "person" property = "pwd" param = "password"/> <BR></jsp:useBean> <BR><% <BR>isnotlogin = person.judge(); <BR>if(!isnotlogin) <BR>{ <BR>response.sendRedirect("error.jsp"); <BR>return; <BR>} <BR>else <BR>{ <BR>session.setAttribute("username", request.getParameter("username")); <BR>%> <BR><jsp:forward page = "sbmt"> <BR><jsp:param name = "username" value = "<%=username%>"/> <BR></jsp:forward> <BR><% <BR>} <BR>%> <BR></body> <BR></html> <BR><BR>register.java(JavaBean)部分: <BR><U>复制代码</U> 代码如下:<BR>package mypack; <BR>public class register { <BR>private String username = ""; <BR>private String pwd = ""; <BR>public void setUserName(String nm) <BR>{ <BR>this.username = nm; <BR>} <BR>public String getUserName() <BR>{ <BR>return this.username; <BR>} <BR>public void setPwd(String pd) <BR>{ <BR>this.pwd = pd; <BR>} <BR>public String getPwd() <BR>{ <BR>return this.pwd; <BR>} <BR>public boolean judge() <BR>{ <BR>boolean temp = false; <BR>if(username.equals("teacher") && pwd.equals("teacher")) <BR>{ <BR>temp = true; <BR>} <BR>return temp; <BR>} <BR>} <BR>sbmt.java(Servlet)部分: <BR>package mypack; <BR>import java.io.IOException; <BR>import java.io.PrintWriter; <BR>import javax.servlet.ServletException; <BR>import javax.servlet.http.HttpServlet; <BR>import javax.servlet.http.HttpServletRequest; <BR>import javax.servlet.http.HttpServletResponse; <BR>import javax.servlet.http.HttpSession; <BR>public class sbmt extends HttpServlet { <BR>private static final long serialVersionUID = 1L; <BR>public sbmt() { <BR>super(); <BR>} <BR>public void destroy() { <BR>super.destroy(); <BR>} <BR>public void doGet(HttpServletRequest request, HttpServletResponse response) <BR>throws ServletException, IOException { <BR>response.setContentType("text/html"); <BR>PrintWriter out = response.getWriter(); <BR>out <BR>.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); <BR>out.println("<HTML>"); <BR>out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); <BR>out.println(" <BODY>"); <BR>out.print(" This is "); <BR>out.print(this.getClass()); <BR>out.println(", using the GET method"); <BR>out.println(" </BODY>"); <BR>out.println("</HTML>"); <BR>out.flush(); <BR>out.close(); <BR>} <BR>public void doPost(HttpServletRequest request, HttpServletResponse response) <BR>throws ServletException, IOException { <BR>HttpSession session = request.getSession(false); <BR>if(session == null) <BR>{ <BR>response.sendRedirect("error.jsp"); <BR>return; <BR>} <BR>String usernameone = (String)session.getAttribute("username"); <BR>String usernametwo = request.getParameter("username"); <BR>if(!usernameone.equals(usernametwo)) <BR>{ <BR>response.sendRedirect("error.jsp"); <BR>return; <BR>} <BR>response.setContentType("text/html;charset = GBK"); <BR>request.setAttribute("username", usernametwo); <BR>if(usernametwo.equals("teacher")) <BR>{ <BR>response.sendRedirect("teacher.jsp"); <BR>return; <BR>} <BR>else <BR>{ <BR>response.sendRedirect("error.jsp"); <BR>return; <BR>} <BR>} <BR>} <BR>} <BR></div> </div> </div> <div class="share"> </div> <div class="nextinfo"> <p>上一篇:<a href="/3g/1/163235.html" title="JSP 多条SQL语句同时执行的方法">JSP 多条SQL语句同时执行的方法</a></p> <p>下一篇:<a href="/3g/1/163237.html" title="IE cache缓存 所带来的问题收藏">IE cache缓存 所带来的问题收藏</a></p> </div> <div class="otherlink"> <h2>最新资源</h2> <ul> <li><a href="/3g/1/623703.html" title="群星《奔赴!万人现场 第2期》[FLAC/分轨]">群星《奔赴!万人现场 第2期》[FLAC/分轨]</a></li> <li><a href="/3g/1/623702.html" title="群星《奇妙浪一夏 (上海迪士尼度假区音乐">群星《奇妙浪一夏 (上海迪士尼度假区音乐</a></li> <li><a href="/3g/1/623701.html" title="群星《奇妙浪一夏 (上海迪士尼度假区音乐">群星《奇妙浪一夏 (上海迪士尼度假区音乐</a></li> <li><a href="/3g/1/623700.html" title="【古典音乐】詹姆斯·高威《季节》1993[WA">【古典音乐】詹姆斯·高威《季节》1993[WA</a></li> <li><a href="/3g/1/623699.html" title="贝拉芳蒂《卡里普索之王》SACD[WAV+CUE]">贝拉芳蒂《卡里普索之王》SACD[WAV+CUE]</a></li> <li><a href="/3g/1/623698.html" title="小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE">小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE</a></li> <li><a href="/3g/1/623697.html" title="群星《欢迎来到我身边 电影原声专辑》[32">群星《欢迎来到我身边 电影原声专辑》[32</a></li> <li><a href="/3g/1/623696.html" title="群星《欢迎来到我身边 电影原声专辑》[FL">群星《欢迎来到我身边 电影原声专辑》[FL</a></li> <li><a href="/3g/1/623695.html" title="雷婷《梦里蓝天HQⅡ》 2023头版限量编号低">雷婷《梦里蓝天HQⅡ》 2023头版限量编号低</a></li> <li><a href="/3g/1/623694.html" title="群星《2024好听新歌42》AI调整音效【WAV分">群星《2024好听新歌42》AI调整音效【WAV分</a></li> </ul> </div> </div> <div class="sidebar"> </div> <div class="sidebar"> 友情链接:<a href="http://www.imxmx.com/" title="杰晶网络" target="_blank">杰晶网络</a> <a href="/" title="DDR爱好者之家" target="_blank">DDR爱好者之家</a> <a href="http://www.nqxw.com/" title="南强小屋" target="_blank">南强小屋</a> <a href="http://www.paidiu.com/" title="黑松山资源网" target="_blank">黑松山资源网</a> <a href="http://www.dyhadc.com/" title="白云城资源网" target="_blank">白云城资源网</a> <a href="/sitemap1.xml">站点地图</a> <a href="/sitemap.xml">SiteMap</a> </div> </article> <footer> <p>Design by <a href="http://m.ddrfans.com">DDR爱好者之家</a> <a href="http://m.ddrfans.com">http://m.ddrfans.com</a></p> </footer> <script src="/images3g/nav.js"></script> <script type="text/javascript"> jQuery.noConflict(); jQuery(function() { var elm = jQuery('#left_flow2'); var startPos = jQuery(elm).offset().top; jQuery.event.add(window, "scroll", function() { var p = jQuery(window).scrollTop(); jQuery(elm).css('position', ((p) > startPos) ? 'fixed' : ''); jQuery(elm).css('top', ((p) > startPos) ? '0' : ''); }); }); </script> </body> </html>