Use IntelliJ idea to develop SPRINGMVC Web site (ii) Framework Configuration

Source: Internet
Author: User

Original: http://my.oschina.net/gaussik/blog/513353

directory [-] The article has made some updates for idea 15, some of which are important, please read the article again and download the latest source code. V. SPRINGMVC Framework Configuration 1, web.xml configuration 2, xxx-servlet.xml configuration

Reprint please specify the Source: Gaussic (a dedicated AI research but have to take into account the project's graduate).

Note: This article to undertake the previous article: use IntelliJ idea to develop SPRINGMVC Web site (i) Development environment

Visit GitHub Download the latest source code: Https://github.com/gaussic/SpringMVCDemo article has been for idea 15 made a certain update, part of the update is more important, please read the article and download the latest source code. Five, SPRINGMVC frame configuration

After the above configuration, it shows that the basic development environment has been set up, now to start the SPRINGMVC Web site development. 1, web.xml configuration

Open the Web.xml file under Src\main\webapp\web-inf\, and slightly update the Web.xml version, you can support some of the more advanced syntax, as follows:?

1 2 3 4 5 6 7 8 9 ? XML version = "1.0" encoding = "UTF-8"?> < Web-app xmlns = "Http://xmlns.jcp.org/xml/ns/javaee" xmlns: xsi = "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation = "Http://xmlns.jcp.org/xml/ns/javaee http: Xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd "Version =" 3.1 "> < display-name >springmvcdemo W EB application</display-name > </web-app >

Add a servlet to <web-app>:
?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 ? xml  Version = "1.0"   encoding = "UTF-8"?> < web-app  xmlns = "Http://xmlns.jcp.org/xml/ns/javaee" & nbsp;         xmlns:xsi = "Http://www.w3.org/2001/XMLSchema-instance"           xsi:schemalocation = "Http://xmlns.jcp.org/xml/ns/javaee  http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd "           Version = "3.1" >        < display-name >SpringMVCDemo Web  application</display-name >        < servlet >           < Servlet-name >mvc-dispatcher</servlet-name >           < Servlet-class >org.springframework.web.servlet.dispatcherservlet</Servlet-class >           < Load-on-startup >1</Load-on-startUp >      </servlet >        < servlet-mapping >  &nbsp ;       < Servlet-name >mvc-dispatcher</servlet-name >           < Url-pattern >/</Url-pattern >      </ servlet-mapping > </web-app >

The servlet name is Mvc-dispatcher (the name can be modified) to intercept the request (Url-pattern to/, to intercept all requests) and to be processed by the background controller of spring MVC. This configuration is required.

In order to be able to process the Chinese POST request, then configure a encodingfilter to avoid the POST request in Chinese garbled situation:?

1 2 3 4 5 6 7 8 9 10 11 12 13 14-15 16 < filter >      < filter-name >encodingfilter</filter-name >    & nbsp < Filter-class >org.springframework.web.filter.characterencodingfilter</Filter-class >       < Init-param >          < param-name >encoding</ Param-name >          < param-value >utf-8</Param-value >      </init-param >      < init-param >     & nbsp;    < Param-name >forceencoding</param-name >           < Param-value >true</param-value >      </init-param > </Filter & Gt < filter-mapping >      < filter-name >encodingfilter</filter-name >       < Url-pattern >/*</Url-pattern > </filter-mapping >

At this point, the Web.xml configuration is complete.
2, xxx-servlet.xml configuration

After Web.xml is configured, you need to create a new mvc-dispatcher-servlet.xml in the Web.xml sibling (-servlet the servlet name defined in the servlet above):

After you create the XML file, click on the Configure in the upper-right corner to appear on the Setup frameworks interface and click OK, so that IntelliJ idea identifies the SPRINGMVC configuration file:

Mvc-dispatcher-servlet.xml files are as follows:?

1 2 3 4 5 6 ? XML version = "1.0" encoding = "UTF-8"?> < beans xmlns = "Http://www.springframework.org/schema/beans" x Mlns:xsi = "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation = "Http://www.springframework.org/schema /beans http://www.springframework.org/schema/beans/spring-beans.xsd "> </beans >

MVC Framework has model, view, controller three parts. Model generally for some basic Java Bean,view for the corresponding page display, controller used to process the request of the website.

Create a new package to save the controller in Src\main\java:

Create a new Java class Maincontroller in the controller package (the name is not fixed and can be arbitrarily taken), and modify the following:

?

package  com.gaussic.contr Oller;   import  Org.springframework.stereotype.Controller; import  org.springframework.web.bind.annotation.RequestMapping; import  Org.springframework.web.bind.annotation.RequestMethod;  /**   *&NBSP;CREATED&NBSP;BY&NBSP;DZKAN&NBSP;ON&NBSP;2016/3/8.   * @Controller public  class  maincontroller {       @RequestMapping ( value =  "/",  method = re
1 2 3 4 5 6 7 8 9

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.