《JAVA实验用户登录代码》由会员分享,可在线阅读,更多相关《JAVA实验用户登录代码(7页珍藏版)》请在金锄头文库上搜索。
1、实验结果部分截图:(1)错误的用户名密码(2)错误提示页(3)正确的用户名密码(4)成功页面实验代码:Login部分: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;public class Login e
2、xtends HttpServlet /* * Constructor of the object. */public Login() super();/* * Destruction of the servlet. */public void destroy() super.destroy(); / Just puts destroy string in log/ Put your code here/* * The doGet method of the servlet. * * This method is called when a form has its tag value met
3、hod equals to get. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletRespons
4、e response)throws ServletException, IOException response.setContentType(text/html);response.setCharacterEncoding(gb2312);PrintWriter out = response.getWriter();out.println();out.println();out.println();out.println(A Servlet);out.println( );out.print();out.print();out.println(用户名:);out.println();out.
5、println();out.println();out.println(密码:);out.println();out.println();out.println();out.println();out.println( );out.println();out.println();out.println();out.println();out.flush();out.close();/* * The doPost method of the servlet
6、. * * This method is called when a form has its tag value method equals to post. * * param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */pu
7、blic void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException doGet(request, response);/* * Initialization of the servlet. * * throws ServletException if an error occurs */public void init() throws ServletException / Put your code hereLoginuser部分:impo
8、rt 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;public class Loginuser extends HttpServlet /* * Constructor of the object. */public
9、 Loginuser() super();/* * Destruction of the servlet. */public void destroy() super.destroy(); / Just puts destroy string in log/ Put your code here/* * The doGet method of the servlet. * * This method is called when a form has its tag value method equals to get. * * param request the request send b
10、y the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */* * The doPost method of the servlet. * * This method is called when a form has its tag value method equals to post. *
11、* param request the request send by the client to the server * param response the response send by the server to the client * throws ServletException if an error occurred * throws IOException if an error occurred */public void doPost(HttpServletRequest request, HttpServletResponse response)throws Se
12、rvletException, IOException User newUser = new User();newUser.userName = request.getParameter(ID_USER);newUser.passWord = request.getParameter(ID_PASS);response.setContentType(text/html);response.setCharacterEncoding(utf-8);PrintWriter out = response.getWriter();out.println();out.println();out.println( A Servlet);