Java web mvc and java webmvc

Source: Internet
Author: User

Java web mvc and java webmvc

1. First, let's briefly introduce what is MVC.

In the description of MVC in Baidu encyclopedia, the full name of MVC is Model View Controller, short for model-view-controller. In JAVA web development, MVC corresponds to: Display page (view), data object (model), and business processing (Controller ).

For example, in the student information management system, the login interface is a view. After the login is complete, the user name and password are judged and the corresponding page is displayed, that is, the controller, the object that saves the user name and password is the model. This is the relationship between the three. The following is an example of a java Dynamic Web page.

2. File structure



3. What to use

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(HttpServletRequest request, HttpServletResponse response) */protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stub}/** * @see HttpServlet#doPost(HttpServletRequest 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 pages are relatively simple and will not be pasted.


What is the MVC pattern of Java Web?

Let's talk about it in plain words. In this way, m database is related. c controller and v show that c is like a transportation hub. He gets the underlying database, that is, m-related things, put it on the front-end to display jsp, html, v, and c as the hub among them.

What is the difference between MVC and the three-tier architecture in JavaWeb?

In short, most of them are literal meanings.
The M model layer mainly involves business logic.
V view (view) layer main foreground display
The C controller (Control) layer mainly controls page jumps to call background Functions

Uitl tool classes are generally common classes.
Entity class
 

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.