<%@ page language= "java" contenttype= "text/html; charset=gb18030 " pageencoding=" GB18030 "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
servletGet the form data, invoke the business logic in the background, and make the page jump.
public class Loginservlet extends HttpServlet {public void doget (HttpServletRequest request, HttpServletResponse Response) throws Servletexception, IOException {//Get the user name and user password sent by the foreground string Username=request.getparameter ("UserName"); String password=request.getparameter ("PassWord");//constructs the user object and assigns the user user=new user (); user.setusername (UserName); User.setpassword (PassWord);//query whether the user exists Usermanager usermanager=new usermanager (); String showinfo=usermanager.queryuser (user);//displays information into Rqeust request.setattribute ("Showinfo", showinfo);// Page redirected to Show.jsprequest.getRequestDispatcher ("/show.jsp"). Forward (request, response);}}
Manager
The manager stores the data as well as the business logic judgment, where it writes a bogus data and determines the business logic with the login username and password.
public class Usermanager {public String queryuser (user user) {User userdb=new User (); Userdb.setusername ("admin"); Userdb.setpassword ("admin"), if (User.getusername (). Equals (Userdb.getusername ()) && User.getpassword (). Equals (Userdb.getpassword ())) {return "Welcome" "+userdb.getusername () +" "Login System";} Return "user does not exist";}}
Time series diagram of a login instance
It is not difficult to find the time series diagram of the Model2 in the previous blog, and the sequence diagram of the login instance can correspond to the lifeline one by one of the Model2 timing diagram. The idea of a single layer of responsibility is also shown, JSP is used to display, the servlet is used to turn the page, and manger is equivalent to model for business logic.
Java Model2 User Login Simple instance