SpringMVC (1)-General Introduction to the process framework

Source: Internet
Author: User

SpringMVC is a follow-up product of SpringFrameWork and has been integrated into Spring Web Flow. The Spring framework provides a full-featured MVC module for Building Web applications. Its functions are similar to those of Strtus2 and Struts1, but the implementation principles are different. Specifically, Struts2 uses filters to implement channel strength and action ing and other control flow functions, while Struts1 and SpringMVC encapsulate their code through the most traditional servlet. But they are all very similar MVC process frameworks. Let's take a brief look at the knowledge points in the SpringMVC framework. Here we divide the data from the order before and after the data flow:


I. SpringMVC is a MVC process framework. It is also applicable to the action module in our presentation layer and is the real Controller in the MVC Architecture mode. SpringMVC is more flexible in process processing and can be easily expanded. It can be seamlessly integrated with the Spring framework. After all, it is produced by a company to solve web development problems and increase competitiveness. However, SpringMVC is invasive. action must inherit the class specified by the framework or implement the specified interface.

2. Let's look at a schematic diagram of its implementation:


And Struts2 is still very similar, there is a core filter Dispatcher, and the core configuration file springMVC-servlet.xml, through filtering to do some fixed tasks, to reach the specified action for related business operations. Let's look at the previous article on the Internet. It is quite detailed: spring MVC principles

Iii. Preliminary use:

1. SpringMVC is developed after Spring. It uses the jar package of Spring. Here, let's take a look at the jar package to be imported:

Commons-logging.jar (log output)

Spring-webmvc.jar (SpringMVC core package)

Spring. jar (Spring core package)

2, write springMVC-servlet.xml files, stored in the/WEB-INF/directory, the basic compilation is as follows:


 
 
  
  
   
   
  
  
  
 
 
 

3. Adding support for the springMVC framework in web. xml is actually adding the servlet configuration of the SpringMVC framework core filter:


 
 
  
   
SpringMVC
  
  
   
Org. springframework. web. servlet. DispatcherServlet
  
  
   
   
    
ContextConfigLocation
   
   
    
/WEB-INF/springMVC-servlet.xml
   
  
  
  
   
1
  
 
 
  
   
SpringMVC
  
  
   
*. Html
  
 

4. The corresponding action is invasive and needs to implement the contronler interface. Of course, you can inherit the parent class that implements this interface, which will be introduced later:


Public class HelloWorldController implements Controller {/*** is similar to Servlet's doGet (), doPost () method */public ModelAndView handleRequest (HttpServletRequest request, HttpServletResponse response) throws Exception {// receives data, including request and response, which facilitates data processing. // calls the service layer. // Determine the returned result // ModelAndView is used to indicate the view: name of the view layer file. (Add the prefix, suffix, and search for configuration resources based on The View parser of the Framework .) // ModelAndView can also represent Model objects and pass data to the view layer. (Redirection is performed by default .) Return new ModelAndView ("success", "username", "zhangsan"); // WEB-INF/jsp/spring/+ success +. jsp }}

This completes the Implementation of the Basic Framework. Many of the construction steps of the framework only require us to pay attention to the details and write the configuration file.


This is the general understanding of SpringMVC. Some of the knowledge points will be summarized later. I will not repeat them here! By comparing Struts2 and Struts2, we can find some similarities and differences and use practices to make our understanding more profound.


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.