Two Spring MVC Build

Source: Internet
Author: User

First, the Guide package

1. Add Spring's core package

2. Add Spring MVC Core Package

Second, configure the front-end controller in Web-info/web.xml Dispatcherservlet
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <Web-appXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns= "Http://java.sun.com/xml/ns/javaee" 3 xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"ID= "webapp_id"version= "3.0">4     <Display-name>Dispatcherservlet</Display-name>5     <servlet>6         <!--Configure the front-end controller in the Spring MVC framework -7         <Servlet-name>Dispatcherservlet</Servlet-name>8         <!--This is the class address that points to the servlet that we want to register, with the package path -9         <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class>Ten         <Init-param> One             <!--initializes the spring configuration file, loads the corresponding XML, and does not load the Applicationcontext.xml under/web-inf/. - A             <Param-name>Contextconfiglocation</Param-name> -             <!--specifies that the specific configuration file is Applicationcontext.xml, which is used by the current servlet to create the context - -             <Param-value>Classpath:applicationContext.xml</Param-value> the         </Init-param> -         <!--The servlet is loaded at startup, the number 1-5 is the servlet's boot order, and 1 is the highest - -         <Load-on-startup>1</Load-on-startup> -         <!--Load-on-startup must be put in the last - +     </servlet> -      +     <!--the access path used to configure the components we register - A     <servlet-mapping> at         <!--Specifies which servlet is configured - -         <Servlet-name>Dispatcherservlet</Servlet-name> -         <!--specifies which requests are blocked to the servlet - -         <Url-pattern>/</Url-pattern> -     </servlet-mapping> - </Web-app>

Third, under the resource configuration Applicationcontext.xml

1 <?XML version= "1.0" encoding= "UTF-8"?>2 <Beansxmlns= "Http://www.springframework.org/schema/beans"3 Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" 4 Xmlns:mvc= "Http://www.springframework.org/schema/mvc"5 Xmlns:context= "Http://www.springframework.org/schema/context"6 XMLNS:AOP= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP" 7 Xmlns:tx= "Http://www.springframework.org/schema/tx"8 xsi:schemalocation= "Http://www.springframework.org/schema/beans9 http://www.springframework.org/schema/beans/spring-beans.xsdTen Http://www.springframework.org/schema/context One http://www.springframework.org/schema/context/spring-context.xsd A Http://www.springframework.org/schema/jee - http://www.springframework.org/schema/jee/spring-jee.xsd - HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP the http://www.springframework.org/schema/aop/spring-aop.xsd - Http://www.springframework.org/schema/tx - http://www.springframework.org/schema/tx/spring-tx.xsd "> -  +     <!--Configuring the processor adapter Handleradapter - -     <!--This adapter can implement the Controller interface to implement the handler, now configure the adapter, all the processor handler must implement the Controller interface . - +     <Beanclass= "Org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />  A      at     <!--Configuring the Processor mapper Handlermapping - -     <!--find the Bean's name as a URL and need to specify Beanname (that is, URL) when configuring handler - -     <Beanclass= "Org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" /> -      -     <!--Configuring the View resolver Viewresolver - -     <!--for JSP parsing, the default use of Jstl tags, classpath under the Jstl package - in     <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver" /> -      to </Beans>

IV. Create a new controller and JSP, and configure the controller to the configuration file

Two Spring MVC Build

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.