<%@ page language="java" pageEncoding="gb2312"%> <html> <head> <title>注册用户</title> </head> <body> <form name="form1" action="zhuce" method="post"> <table width="100%" border="0""> <tr> <td>新用户注册:</td> </tr> <hr align="center"> <tr> <td width="17%">请输入帐号:</td> <td width="83%"> <input name="username1" type="text" id="username" size="15" maxlength="20"> </td> </tr> </table> <hr align="center"> <table width="100%" border="0"> <tr> <td width="17%">请输入用户名:</td> <td width="83%"> <input name="username2" type="text" id="username" size="15" maxlength="20"> </td> </tr> </table> <hr align="center"> <table width="100%" border="0"> <tr> <td width="17%">请输入密码:</td> <td width="83%"> <input name="pwd1" type="password" size="15" maxlength="20"> </td> </tr> </table> <hr align="center"> <table width="100%" border="0"> <tr> <td width="17%"> 密码确认:</td> <td width="83%"> <input name="pwd2" type="password" size="15" maxlength="20"> </td> </tr> </table> <hr align="center"> <table width="100%" border="0"> <tr> <td width="17%">请输入E-MAIL:</td> <td width="83%"> <input name="username3" type="text" id="username" size="25" maxlength="20"> </td> </tr> </table> <hr align="center"> <table width="100%" border="0"> <tr> <td width="17%">请输入常用电话:</td> <td width="83%"> <input name="username4" type="text" id="username" size="15" maxlength="20"> </td> </tr> </table> <hr align="center"> <table width="100%" border="0"> <tr> <td width="17%">请输入收货地址:</td> <td width="83%"> <input name="username5" type="text" id="username" size="50" maxlength="20"> </td> </tr> </table> <hr align="center"> <table width="100%" border="0"> <tr> <td width="17%">请输入邮编:</td> <td width="87%"> <input name="username6" type="text" id="username" size="15" maxlength="20"> </td> </tr> </table> <hr align="center"> <table align="center"> <tr> <td> <input name="zhuce1" type="button"value="注册" onClick="zhuce()"> <input name="zhuce2" type="button" value="取消注册"> </td> </tr> </table> </form> </body> </html> ------------------------------------ package com.xaccp.servlet; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import com.xaccp.daoImpl.UsersDaoImpl; import com.xaccp.entity.Users; public class LoginServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doPost(request, response); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String userName=request.getParameter("userName"); String password=request.getParameter("password"); Users u=new Users(); u.setUserName(userName); u.setPassword(password); UsersDaoImpl dao=new UsersDaoImpl(); if(dao.checkLogin(u)) { Users LoginUser=dao.findUsersByName(userName); HttpSession session=request.getSession(); session.setAttribute("LoginUser", LoginUser); response.sendRedirect("/addressBook/SelectServlet"); } else { response.sendRedirect("/addressBook/index.jsp"); } } } 上面这上登录验证的Servlet 下面上配置web.xml配置文件 <servlet> <description>This is the description of my J2EE component</description> <display-name>This is the display name of my J2EE component</display-name> <servlet-name>LoginServlet</servlet-name> <servlet-class>com.xaccp.servlet.LoginServlet</servlet-class> </servlet> 下满上登录页面的form <form name="login" action="loginServlet" method="post" οnsubmit="return checkLongin()"> <TABLE width="100%" style="cellpadding: 0px; cellspacing: 0px; margin-top: 0px; margin-Left: 0px" style="table-layout: fixed;WORD-BREAK: break-all; WORD-WRAP: break-word"> <TR> <TD style="color:#4c4743;line-height:160%;" valign="top" width="30%">用户名:</TD> <TD style="color:#4c4743;line-height:160%;" valign="top"><input type="text" name="userName" value="<%=userName %>"/></TD> <TD style="color:#4c4743;line-height:160%;"><a href="register.jsp">注册</a></TD> </TR> <TR> <TD style="color:#4c4743;line-height:160%;" valign="top" width="30%">密 码</TD> <TD style="color:#4c4743;line-height:160%;" valign="top"><input type="password" name="password" /></TD> </TR> <TR> <TD style="color:#4c4743;line-height:160%;" valign="top" width="30%"><input type="submit" value="提交" /></TD> <TD style="color:#4c4743;line-height:160%;" valign="top"><input type="reset" value="重置" /></TD> </TR> </TABLE> </td> <td width="47" valign="top" background="image/flower/m_bg.jpg"> </td> </tr> </table> </form>
servlet 转发请求
最新推荐文章于 2021-04-24 11:25:23 发布