SPRINGMVC Introduction Configuration and HelloWorld instance

Source: Internet
Author: User

1. Create a new Web project

2. Copy the required Jar to Lib

3. Overwrite Web. xml

<?xml version= "1.0" encoding= "UTF-8"? ><web-app version= "3.0" 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_3_0.xsd ">  <display-name></display-name>  < welcome-file-list>    <welcome-file>index.jsp</welcome-file>  </welcome-file-list>    <servlet>  <servlet-name>springMVC</servlet-name>  <servlet-class> Org.springframework.web.servlet.dispatcherservlet</servlet-class>    <load-on-startup>1</ load-on-startup>  </servlet>  <servlet-mapping>  <servlet-name>springmvc</ servlet-name>  <url-pattern>/</url-pattern>  </servlet-mapping>  </web-app >

4. Create a new springmvc-servlet.xml under Web-inf

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" Xmlns:xs I= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p" xmlns:context= "H Ttp://www.springframework.org/schema/context "xmlns:mvc=" Http://www.springframework.org/schema/mvc "Xsi:sche malocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/sche Ma/beans/spring-beans-3.0.xsd Http://www.springframework.org/schema/context Http://www.sprin                Gframework.org/schema/context/spring-context-3.0.xsd HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/MVC Http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd "> <!--viewresolver View Resolver--&L T;bean id= "Viewresolver" class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" > < Property name= "prefix" value= "/web-inf/"/> <property name=" suffix "value=". jsp "/> </bean> </beans> 

  

5. New Package:com.tgb.web.controller Class:HelloWorldController.java under SRC

Package Com.tgb.web.controller;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import Org.springframework.stereotype.controller;import Org.springframework.web.servlet.modelandview;public class Helloworldcontroller Implements org.springframework.web.servlet.mvc.controller{@Overridepublic modelandview handlerequest (httpservletrequest arg0 , HttpServletResponse arg1) throws Exception {System.out.println ("---hello wly--------"); return new Modelandview ("/ Welcome ");}}

6. New welcome.jsp, under Web-inf

7. Modify the configuration file Springmvc-servlet.xml

<bean name= "/test1/helloworld" class= "Com.tgb.web.controller.HelloWorldController" ></bean>

  

8. IE Test: Http://localhost:8080/springMVC1/test1/helloworld

SPRINGMVC Introduction Configuration and HelloWorld instance

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.