admin 管理员组

文章数量: 887021


2024年1月16日发(作者:defaultstatus)

} } if (statement != null) { try { (); } catch (SQLException e) { tackTrace(); } } if (rs != null) { try { (); } catch (SQLException e) { tackTrace(); } } }}登录servletpackage ;import ption;import tException;import ;import rvlet;import rvletRequest;import rvletResponse;public class Login extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { tentType("text/html;charset=UTF-8"); racterEncoding("UTF-8"); Cookie[] cookies = kies(); String username = ""; String password = ""; String chck=""; if (cookies != null) { for (Cookie cookie : cookies) { if (e().equals("username")) { username = ue(); chck ="checked='checked'"; } if (e().equals("password")) { password = ue(); } } } ter().write("

" + " 姓名:
" + " 密码:
" + " 记住密码:
" + " " + "
"); } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); }}处理登录请求servlet

package ;import ption;import riter;import edStatement;import Set;import eption;import tion;import tException;import ;import rvlet;import rvletRequest;import rvletResponse;public class work1 extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { tentType("text/html;charset=UTF-8"); racterEncoding("UTF-8"); PrintWriter writer = ter(); String sql = "select * from users where username=? and password=?"; String username = ameter("username"); String password = ameter("password"); String chck = ameter("chck");

Connection connection = nection(); PreparedStatement prepareStatement = null; try { prepareStatement = eStatement(sql); ing(1, username); ing(2, password); ResultSet rs = eQuery(); while (()) { String user = ing("username"); String pw = ing("password"); if ((username) && (password)) { ter().write("登录成功"); Cookie cookie1 = new Cookie("username", username); Cookie cookie2 = new Cookie("password", password); h("/"); h("/"); if (chck != null) { Age(60*5); Age(60*5); } else { Age(0); Age(0); } kie(cookie1); kie(cookie2); ter().write(username); ter().write(password); } else { ter().write("登录失败嗷"); der("refresh", "3;/day33work/login"); } } } catch (SQLException e) { tackTrace(); } } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); }

}配置

ml/ns/javaee /xml/ns/javaee/web-app_3_" id="WebApp_ID" version="3.0"> day33work

login login /login

work1 1 work1 /work1

schemaLocation="/x


本文标签: 登录 记住 密码