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?
- <? XML version= "1.0" encoding="UTF-8" ?>
- <! DOCTYPE beans Public "-//spring//dtd BEAN 2.0//en" "Http://www.springframework.org/dtd/spring-beans-2.0.dtd " >
- <beans>
- <!--view definitions, the framework provides a lot of parsers, here are examples of one--
- <Bean id= "viewresolver" class=" Org.springframework.web.servlet.view.InternalResourceViewResolver ">
- <property name= "prefix" value="/web-inf/jsp/spring/"/>
- <property name="suffix" value= ". jsp"/>
- </Bean>
- <!--definitions of public CONTROLLERS, map parser--
- <Bean id= "defaulthandlermapping" class=" Org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping "/>
- </Beans>
- <!--Controller class, name represents the URI path of the Access, class represents the corresponding action class --
- <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?
- <!--SPRINGMVC Core Controller (front Controller)--
- <servlet>
- <servlet-name>springmvc</servlet-name>
- <servlet-class>org.springframework.web.servlet.dispatcherservlet</ Servlet-class>
- <init-param>
- <!--Specifies the full name of the configuration file, if not specified, springmvc+ "-servlet.xml" for the Servlet-name property here
- <param-name>contextconfiglocation</param-name>
- <param-value>/web-inf/springmvc-servlet.xml</param-value>
- </init-param>
- < Create this Serlvet core object when you start the server!-- -
- <load-on-startup>1</load-on-startup>
- </servlet>
- <servlet-mapping>
- <servlet-name>springmvc</servlet-name>
- <url-pattern>*.html</url-pattern>
- </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?
- Public class Helloworldcontroller implements Controller {
- /**
- * Similar to Servlet's Doget (), DoPost () method
- */
- Public Modelandview HandleRequest (httpservletrequest request,httpservletresponse response) throws Exception {
- //Receive data, there are request,response and so on, for data processing convenient a lot
- //Call the service layer.
- //Judgment return result
- //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.) )
- //modelandview can also represent model objects and pass data to the view layer. (by default, jumps are made by forwarding.) )
- return new Modelandview ("Success","username", "Zhangsan"); ///web-inf/jsp/spring/+ success +. JSP
- }
- }
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