Developing SPRINGMVC with annotations

Source: Internet
Author: User

1. importing the jar Package

Commons-logging-1.2.jar

Spring-aop-4.3.6.release.jar

Spring-beans-4.3.6.release.jar

Spring-context-4.3.6.release.jar

Spring-context-support-4.3.6.release.jar

Spring-core-4.3.6.release.jar

Spring-expression-4.3.6.release.jar

Spring-web-4.3.6.release.jar

Spring-webmvc-4.3.6.release.jar

Taglibs-standard-compat-1.2.5.jar

Taglibs-standard-impl-1.2.5.jar

Taglibs-standard-jstlel-1.2.5.jar

Taglibs-standard-spec-1.2.5.jar

2.web.xml Configuration

<?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>01springmvc_mvc</Display-name>  <servlet>    <Servlet-name>Springmvc</Servlet-name>    <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class>    <Init-param>        <Param-name>Contextconfiglocation</Param-name>        <Param-value>Classpath:mvc.xml</Param-value>    </Init-param>    <Load-on-startup>1</Load-on-startup>  </servlet>    <servlet-mapping>    <Servlet-name>Springmvc</Servlet-name>    <Url-pattern>*.do</Url-pattern>  </servlet-mapping>  <welcome-file-list>    <Welcome-file>index.jsp</Welcome-file>  </welcome-file-list></Web-app>

Attention:

 <  init-param         >  <  param-name  >  contextconfiglocation</ param-name  >   <  param-value  >  classpath: Mvc.xml</ param-value  >  </ init-param  >  

Indicates the configuration file location (src/mvc.xml) Focus of MVC

3.Controller

 Public class Hellocontroller {    @RequestMapping ("/hello")    public  Modelandview Hello ( HttpServletRequest req, HttpServletResponse resp) {        new  Modelandview ();         // encapsulate the data        to be displayed in the view Mav.addobject ("msg", "Hello Springmvc");         // View name        Mav.setviewname ("Hello");         return Mav;}    }

4.SPRINGMVC Configuration

<?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"Xmlns:context= "Http://www.springframework.org/schema/context"xsi:schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/beans/spring-beans. XSD Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-conte Xt.xsd ">    <!--Configuring the Renderer -    <BeanID= "Jspviewresolver"class= "Org.springframework.web.servlet.view.InternalResourceViewResolver">        < Propertyname= "Viewclass"value= "Org.springframework.web.servlet.view.JstlView"/>        <!--the prefix of the result view -        < Propertyname= "prefix"value= "/web-inf/jsp/"/>        <!--suffix of the result view -        < Propertyname= "suffix"value= ". jsp"/>    </Bean>    <!--Scan for annotations under this package -    <Context:component-scanBase-package= "Com.springmvcanno"/></Beans>

Developing SPRINGMVC with annotations

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.