1. The configuration of the front controller Dispatcherservlet is configured in Web. XML to be the same as the servlet configuration
1) contextconfiglocation configuration Sprimgmvc loaded configuration file (Configuration Processor mapper, adapter, etc.) if Contextconfiglocation is not configured, the default load is/web-inf/ Servlet name-servlet.xml (springmvc-servlet.xml)
2)
The first type: *.action, accessed with. Action ends resolved by Dispatcherservlet
The second:/All Access addresses are parsed by Dispatcherservlet, and the parsing of static files needs to be configured not to allow Dispatcherservlet to parse, this way can implement restful style URL
The third type:/* This configuration is not correct, using this configuration will eventually be forwarded to a JSP page, still by Dispatcherservlet parsing JSP address, can not be based on
JSP page found handler, this way is wrong
<servlet> <servlet-name>springmvc</servlet-name> <servlet-class> Org.springframework.web.servlet.dispatcherservlet</servlet-class> <!-- Contextconfiglocation Configure SPRIMGMVC loaded configuration file (Configure Processor mapper, adapter, etc.) if Contextconfiglocation is not configured, the default load is/web-inf/ Servlet name-servlet.xml (springmvc-servlet.xml) - <init-param> <param-name> Contextconfiglocation</param-name> <param-value>classpath:springmvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <!-- The first type: *.action, Access to the. Action end is parsed by Dispatcherservlet and the second:/All Access addresses are parsed by Dispatcherservlet. For static file parsing needs to be configured not to allow Dispatcherservlet to parse, this way can implement the restful style of the URL of the third type:/* This configuration is not correct, using this configuration will eventually be forwarded to a JSP page, Still by Dispatcherservlet parsing JSP address, can not find handler based on JSP page, this way is wrong--and <SERVLET-NAME>SPRINGMVC </servlet-name> <url-pattern>*.action</url-pattern> </servlet-mapping>
For Dispatcherservlet We can associate the source code:
The above related source code: can draw the conclusion: Dispatcherservlet actually is indirectly inherits the HttpServlet class, therefore we can say Dispatcherservlet is a servlet, This also shows that SPRINGMVC is a single-mode framework (because servlets are singleton).
2. Configuring the processor mapper in Springmvc.xml
<!--1. Configuring the Processor Mapper by name, you find the URL based on the name attribute in the bean, so you need to configure the Name property- <bean class= "When you configure handler" Org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping "></bean> <!--2. Configuring the Simple processor Mapper-- > <bean class= "org.springframework.web.servlet.handler.SimpleUrlHandlerMapping" > <property Name= "Mappings" > <props> <!--key is the configured mapping path at this time the processor hander must specify id--> <prop key= " Queryitems1.action ">itemController1</prop> <prop key=" Queryitems2.action ">itemcontroller2 </prop> </props> </property> </bean>
3. Configuring the Processor Adapter
<!--1. Configuring the processor adapter requires the core handler to implement the Controller interface-- <bean class= " Org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter "></bean> <!--2. Configuring the processor adapter-- > <bean class= "Org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter" ></bean>
Associated Source code:
4. Configure Handler
<!--configuration Handler-- <bean name= "/queryitems.action" class= " Cn.itcast.ssm.controller.ItemController1 "></bean> <bean id=" ItemController2 " class=" Cn.itcast.ssm.controller.ItemController2 "></bean>
The first itemController1 is to find the URL based on the first way the mapper is configured, which requires the Name property to be set
The second ItemController2 configures the ID property to find the URL based on the second mapper, and the property that has the key configured in the processor mapper is the URL
5. Configure the View resolver
<!--configuration View Resolver-- <bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > </bean>
This view parser resolves a jsp page
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
SPRINGMVC Front Controller, Mapper, adapter, view resolver