1, first briefly introduce what is the MVC idea.
In the Baidu Encyclopedia of the MVC description, the full name ofMVC is the Model View controller, is the models-view (the controller) abbreviation. So in Java Web Development, MVC corresponds to: Display page (view), data object (model), Business Processing (Controller), respectively.
For example, in the Student Information management system, the login interface is a view, and after the completion of the login, the user name and password to determine and jump to the corresponding page, is the controller, and save the user name and password object, is the model. This is the relationship between the three. Below we give an example of a Java Dynamic Web page.
2. File structure
3, the need to use the
tomcat7.0
4. Code structure
Usercheck
Package Com.test.dao;import Com.test.vo.user;public class Usercheck {public boolean login (user user) {if ( User.getusername (). Equals ("admin") && User.getpassword (. Equals ("123456")) return True;return false;}}
Userlogin
Package Com.test.service;import Java.io.ioexception;import Javax.servlet.servletexception;import Javax.servlet.annotation.webservlet;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Com.test.dao.usercheck;import com.test.vo.user;/** * Servlet Implementation class Userlogin */@WebServlet ("/userlogin public class Userlogin extends HttpServlet {private static final long serialversionuid = 1L; /** * Default constructor. */Public Userlogin () {//TODO auto-generated constructor stub}/** * @see Httpservlet#doget (httpservletrequ EST request, httpservletresponse response) */protected void doget (HttpServletRequest request, HttpServletResponse Response) throws Servletexception, IOException {//TODO auto-generated method stub}/** * @see httpservlet#dopost (httpserv Letrequest request, httpservletresponse response) */protected void DoPost (HttpServletRequest request, HttpServletResponse REsponse) throws Servletexception, IOException {//TODO auto-generated method Stubuser u=new User (); U.setusername (Request . GetParameter ("username")); U.setpassword (Request.getparameter ("password")); System.out.println (Request.getparameter ("username") + "" +request.getparameter ("password")); Usercheck dao=new Usercheck (); if (Dao.login (U)) {Response.sendredirect ("login_s.jsp");} Else{response.sendredirect ("login_f.jsp");}}}
User
Package Com.test.vo;public class User {private string Username;public string GetUserName () {return username;} public void Setusername (String username) {this.username = username;} Public String GetPassword () {return password;} public void SetPassword (String password) {this.password = password;} private String password;}
Static page is relatively simple, it is not posted up.
Introduction to Java Web MVC ideas