SPRINGMVC Environment Configuration

Source: Internet
Author: User

The SPRINGMVC environment primarily requires spring's core Libraries and Web Libraries, which can be added directly using MyEclipse. Note: Use the official lib when you need to add Com.springsource.org.apache.commons.logging-1.1.1.jar, otherwise you will get an error.

Spring-mvc.xml

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"Xmlns:tx= "Http://www.springframework.org/schema/tx"Xmlns:context= "Http://www.springframework.org/schema/context"Xmlns:mvc= "Http://www.springframework.org/schema/mvc"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-3.1.xsd Http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring- Tx-3.1.xsd Http://www.springframework.org/schema/context Http://www.springframework.org/schema/context/spring-co Ntext-3.1.xsd Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1 . xsd ">      <!--activate tags such as @required @Autowired @Resource -<Context:annotation-config/><!--Dispatcherservlet context, specifying the class to scan for controller annotations -<Context:component-scanBase-package= "Com.demo"><Context:include-filtertype= "Annotation"expression= "Org.springframework.stereotype.Controller"/></Context:component-scan> <!--support for the default annotation mappings -   <Mvc:annotation-driven/>  <!--Specify the directory of the view and the suffix of the file -<Beanclass= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> < Propertyname= "prefix"value= "/web-inf/jsp/"/> < Propertyname= "suffix"value= ". jsp"/></Bean></Beans>

Applicationcontext.xml

<?XML version= "1.0" encoding= "UTF-8"?><Beansxmlns= "Http://www.springframework.org/schema/beans"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns:p= "http://www.springframework.org/schema/p"xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"></Beans>

Xml

<?XML version= "1.0" encoding= "UTF-8"?><Web-appXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns= "Http://java.sun.com/xml/ns/javaee"xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"version= "3.0">    <Display-name>Springmvc</Display-name>  <Listener>    <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class>  </Listener>     <servlet>    <Servlet-name>Mvc-dispatcher</Servlet-name>    <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class>    <!--Dispatcherservlet The corresponding context configuration -    <!--The following specifies the location of the loaded Mvc-dispatcher-servlet.xml -    <Init-param>      <Param-name>Contextconfiglocation</Param-name>      <Param-value>/web-inf/configs/spring-mvc.xml</Param-value>      </Init-param>     <Load-on-startup>1</Load-on-startup>     </servlet>          <servlet-mapping>     <Servlet-name>Mvc-dispatcher</Servlet-name>     <!--Configure the type of interception request -     <Url-pattern>/</Url-pattern>     </servlet-mapping>        <Context-param>        <Param-name>Contextconfiglocation</Param-name>        <Param-value>Classpath:applicationContext.xml</Param-value>      </Context-param></Web-app>

Demo.java

 Package Com.demo; Import Org.springframework.stereotype.Controller; Import org.springframework.web.bind.annotation.RequestMapping, @Controller @requestmapping ("/hello")  Public class Demo {    @RequestMapping ("/one") public String Hello () {      return "Hello";}}

This is primarily the writing of these three profiles, and then placing the JSP file in the corresponding folder. The last access path is:/HTTP server address: Port/requestmapping of the requestmapping/method of the project name/class

SPRINGMVC Environment 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.