JSP-ServLet 一个简单的密码核对
First Step: Create One Jsp file: [color=blue]Login[/color].jsp This is my JSP page.
Login Password
Second Step: Create One ServLet File: [color=red]LoginServLet[/color].java public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name =request.getParameter("username"); String password=request.getParameter("pwd"); HttpSession session=request.getSession(); if (name.equals("dgy")&&password.equals("123")){ System.out.println("login Successfully"); session.setAttribute("username",name); session.setAttribute("password",password); request.getRequestDispatcher("LoginSuccess.jsp").forward(request, response); }else{ System.out.println("Oops!!! pls correct"); response.sendRedirect("[color=blue]Login[/color].jsp"); } } Third Step: Creat another jsp: LoginSuccess.jsp This is my JSP page.
Username:${username} Password:${password}