SPRINGMVC application Configuration

Source: Internet
Author: User

1. Increase Spring Support

To create a new Web project, add the following jar package:

Commons-logging-1.2.jar Spring-aop-4.2.5.release.jar Spring-aspects-4.2.5.release.jar Spring-beans-4.2.5.release.jar

Spring-context-4.2.5.release.jar Spring-context-support-4.2.5.release.jar Spring-core-4.2.5.release.jar Spring-expression-4.2.5.release.jar

Spring-instrument-4.2.5.release.jar Spring-instrument-tomcat-4.2.5.release.jar Spring-jdbc-4.2.5.RELEASE.jar Spring-jms-4.2.5.release.jar

Spring-messaging-4.2.5.release.jar Spring-orm-4.2.5.release.jar Spring-oxm-4.2.5.release.jar Spring-test-4.2.5.release.jar

Spring-tx-4.2.5.release.jar Spring-web-4.2.5.release.jar Spring-webmvc-4.2.5.release.jar

Spring-webmvc-portlet-4.2.5.release.jar Spring-websocket-4.2.5.release.jar

2. Configure the front-end controller Dispatcherservlet

Configure the Web. xml file (add Dispatcherservlet configuration)

<! --Define spring MVC's Front controller--

<servlet>

<servlet-name>springmvc</servlet-name>

<sevlet-class>org.springframework.web.servlet.DispacherServlet</servlet-class>

<init-param>

<param-name>contextConfigLocation</param-name>

<param-value>/WEB-INF/spring-config.xml</param-value>

</init-param>

<load-on-startup>1</load-on-stratup>

</servlet>

<servlet-mapping>

<servlet-name>springmvc</servlet-name>

<url-pattern>/</url-pattern>

</servlet-mapping>

3, configure the controller SPRINGMVC

Configure the configuration file for Springmvc Spring-config.xml

<beans>

  <!--configure handle, map "Hello" request--

<beanname= "/hello" class= "Org.fkit.conttroler.HelloController"/>

  <!--processing Mapper looks up the bean as a URL and needs to specify the name (that is, the URL) when configuring handle.

<bean class= "org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>

  <!--Simplecontrollerhandleradapter is a processor adapter that implements the Handleradapter interface for all processor adapters--

<bean class= "Org.springframework.web.servler.mvc.SimpleControllerHandlerAdapter"/>

  <!--configuration View Resolver--

<bean class= "Org.springframework.web.servlet.view.InternalResourceViewResolver"/>

</beans>

4, the Controller class implementation

The Controller class must implement the Controller interface to handle/hello requests. (or use @controller annotations directly)

public class Hellocontroller implements controller{

Private static final Log logger = Logfactory.getlog (HELLOCONTROLLER.CALSS);

@Override

Public Modelandview HandleRequest (httpservletrequest request,httpservletresponse response) throws exception{

Logger.info ("HandleRequest is called");

Modelandview mv = new Modelandview ();

Mv.addobject ("message", "Hello world!");

Mv.setviewname ("/web-inf/content/welcome.jsp");

return MV;

}

}

5. View Page

<body>

<!--page to access the message--> passed by the controller

${requestscope.message}

</body>

6. Test Application

Http://localhost:8080/SpringmVCTest/hello

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