SPRINGMVC can be understood to be used to do data display processing framework, the main content is the controller and view processing.
Continue with the following steps (I'm using the MyEclipse2014) based on the spring framework already installed.
1. Modify the Web. xml file
2. Create a SPRINGMVC configuration file in the Web-inf directory
3. Create a new package to put the controller
4. Create the Controller class in the package
5. Access the corresponding address
No nonsense, direct dry!!! 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0001.gif "alt=" J_0001.gif "/>
I. Modifying the Web. xml file
<servlet> <servlet-name>spmvc</servlet-name> <servlet-class>org.springframework.web. Servlet. dispatcherservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>spmvc< ;/servlet-name> <url-pattern>*.form</url-pattern> </servlet-mapping>
Second, create the SPRINGMVC configuration file in the Web-inf directory
<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "http://www.springframework.org/ Schema/beans "xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance "xmlns:aop=" http://www.springframework.org/ Schema/aop "xmlns:context=" Http://www.springframework.org/schema/context "xmlns:mvc="/HTTP/ Www.springframework.org/schema/mvc "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.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/ spring-aop-3.1.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/ context/spring-context-3.1.xsdhttp://www.springframework.org/schema/mvc http://www.springframework.org/ Schema/mvc/spring-mvc-3.1.xsd "><!-- Autoenrollment of defaultannotationhandlermapping and annotationmethodhandleradapter two beans is required for SPRING&NBSP;MVC to distribute the request for @controllers --><mvc:annotation-driven></mvc:annotation-driven><!-- Automatically scans the path of the base-package or the Java file under the sub-package of the path, If you scan to a file with @service, @Component, @Repository, @Controller and other classes of these annotations, register these classes as Bean --><context: Component-scan base-package= "Com.pxy.web.controller" ></context:component-scan></beans>
Third, the creation of the controller's package (please sir do it yourself, because I do not know what the name of your hobby WOW! - -)
Four, create the controller class in the package, here the two annotations (@Controller that the current class is the Controller class, @RequestMapping used to set the access path)
@Controller @requestmapping ("yy") public class Mycontroller {@RequestMapping ("/go") public String Goindex () {R Eturn ". /index.jsp "; }}
@RequestMapping Common properties are as follows, you can play after the normal access to their own!
|
Property name |
Description |
| Value |
specifies the actual address of the request, the specified address can be URI Template mode, which uses the most |
| method |
Specifies the requested method GET , post PUT , delete |
| Consumes |
Specifies the type of submission to process the request ( Content-type ), such as Application/json, text/html |
| Produces |
Specifies the type of content returned, only if Request in the request header Accept is returned when the type contains the specified type. |
| Params |
Specify Request must contain some parameter values before using this method to handle |
| Headers |
Specify Request must contain some of the specified Header value to use this method to process the request |
V. Access to yy/go.form resources in the project.
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M02/9D/E5/wKioL1mILYmBWsyBAAAnsflyOD8395.png "title=" 11. PNG "alt=" Wkiol1milymbwsybaaansflyod8395.png "/>
See, the use of SPRINGMVC is not super simple, come and take refuge in my Buddha! 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0028.gif "alt=" J_0028.gif "/>
This article is from the "Software Thinking" blog, please be sure to keep this source http://softi.blog.51cto.com/13093971/1954251
Java from getting started to giving up: basic usage of SPRINGMVC