Introduction to Java Web MVC ideas

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.