SPRINGMVC (i)--general introduction to the process framework

Source: Internet
Author: User

SPRINGMVC is a follow-on product of Springframework, which has been integrated into spring Web flow. The Spring framework provides a full-featured MVC module for building WEB applications , with functionality and Strtus2, andStruts1 is similar, except that the principle of implementation is different. Struts2 is a filter to achieve road strength and action mapping and other control functions, while Struts1 and Springmvc are the most traditional Servlet to implement encapsulation of its code. But they are very similar to the MVC process framework. Simply take a look at the knowledge points in the SPRINGMVC framework, which are divided into the order of the data before and after the flow:

One,Springmvc is an MVC process framework that also applies to our presentation layer to the action module, which is the real Controller in the MVC architecture pattern . . Springmvc is more flexible in process processing and can be easily extended to seamlessly integrate with the Spring framework, which is produced by a company that solves Web development problems and increases competitiveness. But Springmvc is intrusive, theaction needs to inherit the class specified by the framework, or implement the specified interface.

two, see a schematic of its implementation:

and Struts2 is still very similar, there is a core filter Dispatcher, and the core configuration file Springmvc-servlet.xml, by filtering to do some fixed tasks, to reach the specified Action for business-related operations. Read an article on the Internet, written in a very detailed:spring MVC principle

Third, preliminary use:

1, since Springmvc was developed following spring , it took advantage of Spring 's jar package and looked at the jar packages that needed to be imported :

Commons-logging.jar (log output)

Spring-webmvc.jar (SPRINGMVC core Pack)

Spring.jar (Spring core pack)

2, write springmvc-servlet.xml files , stored in the/web-inf/directory , basically write the following:

[HTML]View Plaincopyprint?
  1. <? XML version= "1.0" encoding="UTF-8" ?>
  2. <! DOCTYPE beans Public "-//spring//dtd BEAN 2.0//en" "Http://www.springframework.org/dtd/spring-beans-2.0.dtd " >
  3. <beans>
  4. <!--view definitions, the framework provides a lot of parsers, here are examples of one--
  5. <Bean id= "viewresolver" class=" Org.springframework.web.servlet.view.InternalResourceViewResolver ">
  6. <property name= "prefix" value="/web-inf/jsp/spring/"/>
  7. <property name="suffix" value= ". jsp"/>
  8. </Bean>
  9. <!--definitions of public CONTROLLERS, map parser--
  10. <Bean id= "defaulthandlermapping" class=" Org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping "/>
  11. </Beans>
  12. <!--Controller class, name represents the URI path of the Access, class represents the corresponding action class --
  13. <Bean name= "/hello.html" class="Com.ljh.springmvc.controller.HelloWorldController" ></beans>


3, Adding support for the SPRINGMVC framework in Web. XML is actually the configuration of the servlet that adds The SPRINGMVC Framework core filter :

[HTML]View Plaincopyprint?
  1. <!--SPRINGMVC Core Controller (front Controller)--
  2. <servlet>
  3. <servlet-name>springmvc</servlet-name>
  4. <servlet-class>org.springframework.web.servlet.dispatcherservlet</ Servlet-class>
  5. <init-param>
  6. <!--Specifies the full name of the configuration file, if not specified, springmvc+ "-servlet.xml" for the Servlet-name property here
  7. <param-name>contextconfiglocation</param-name>
  8. <param-value>/web-inf/springmvc-servlet.xml</param-value>
  9. </init-param>
  10. < Create this Serlvet core object when you start the server!-- -
  11. <load-on-startup>1</load-on-startup>
  12. </servlet>
  13. <servlet-mapping>
  14. <servlet-name>springmvc</servlet-name>
  15. <url-pattern>*.html</url-pattern>
  16. </servlet-mapping>


4, the corresponding action is intrusive, you need to implement the Contronller interface, of course, you can also inherit the implementation of this interface of the parent class, behind the introduction to:

[Java]View Plaincopyprint?
  1. Public class Helloworldcontroller implements Controller {
  2. /** 
  3. * Similar to Servlet's Doget (), DoPost () method
  4. */
  5. Public Modelandview HandleRequest (httpservletrequest request,httpservletresponse response) throws Exception {
  6. //Receive data, there are request,response and so on, for data processing convenient a lot
  7. //Call the service layer.
  8. //Judgment return result
  9. //modelandview is used to represent views: give the name of the view layer file. (depending on the frame's view parser, add the prefix, and the suffix, to find the configuration resource.) )
  10. //modelandview can also represent model objects and pass data to the view layer. (by default, jumps are made by forwarding.) )  
  11. return new Modelandview ("Success","username", "Zhangsan"); ///web-inf/jsp/spring/+ success +. JSP
  12. }
  13. }


In this way, the basic framework implementation is completed, many frameworks are built in these steps, but we need to pay attention to the details of the configuration file, and so on.

Springmvc 's general understanding is these, the back will summarize some of the knowledge points, here no longer repeat! By contrast with the Struts2 study, to find some similarities and differences, through practice to make their understanding more profound.

Springmvc (i)--Overview of the process framework

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.