Spring MVC Environment Setup and configuration

Source: Internet
Author: User

1. Create a Dynamic Web project

2. Modify the Web-inf/web.xml as follows:

<?XML version= "1.0" encoding= "UTF-8"?><Web-appversion= "2.5"xmlns= "Http://java.sun.com/xml/ns/javaee"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">    <servlet>        <Servlet-name>Springmvc</Servlet-name>        <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class>        <Init-param>            <Param-name>Contextconfiglocation</Param-name>            <Param-value>/web-inf/applicationcontext.xml</Param-value>        </Init-param>    </servlet>    <servlet-mapping>        <Servlet-name>Springmvc</Servlet-name>        <Url-pattern>/</Url-pattern>    </servlet-mapping></Web-app>  

3. Create/web-inf/applicationcontext.xml and add the following:

    <Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/be Ans/spring-beans-3.0.xsd Http://www.springframework.org/schema/context Http://www.springframewo Rk.org/schema/context/spring-context-3.0.xsd ">                 <Context:component-scanBase-package= "Com.vito.action" />                 <Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver">              < Propertyname= "prefix">                              <!--This configuration is the location of the JSP page, which is configured according to your -                  <value>/web-inf/view/</value>              </ Property>              < Propertyname= "suffix">                  <value>. jsp</value>              </ Property>          </Bean>             </Beans>  

4. Create a Java file, note the package name

 Packagecom.vito.action; ImportOrg.springframework.stereotype.Controller; ImportOrg.springframework.ui.ModelMap; Importorg.springframework.web.bind.annotation.RequestMapping; ImportOrg.springframework.web.bind.annotation.RequestMethod; @Controller @RequestMapping ("/welcome")   Public classHelloworldcontroller {@RequestMapping (value= "/hello", method =requestmethod.get) PublicString Printwelcome (Modelmap model) {Model.addattribute ("Message", "Spring 3 MVC Hello World"); return"Hello"; }  } 

5. "Key" Create Web-inf/lib, import the following jar package, take care not to fill in the extra package. Because all the sping jar packages were imported before, resulting in an error, it took a day to find the cause.

6. Add the above jar to the build path

7. Try Http://localhost:8080/DemoSpringMVC/welcome/hello!

Spring MVC Environment Setup and configuration

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.