Version Description
Eclipse:eclipse Java EE IDE for WEB developers
Version:luna Release (4.4.0)
tomcat:apache-tomcat-7.0.56
Springmvc:3.2.3.release
File Structure
SPRINGMVC required Jar
Steps 1, the establishment of Web projects
Use Eclipse to build dynamic Web Project. The specific process is slightly. 2. Modify Web.xml file
<?xml version= "1.0" encoding= "UTF-8"?> <web-app xmlns: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 "id=" webapp_id "version=" 3.0 "> <display-name>springmvc</ display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </
welcome-file-list> <!--Spring MVC--> <servlet> <servlet-name>SpringMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- The location and name of the custom servlet.xml configuration file, under the default Web-inf directory, named [<servlet-name>]-servlet.xml--> <init-param> < Param-name>contextconfiglocation</param-name> <param-value>/web-inf/config/springmvc-servlet.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <Servlet-mapping> <servlet-name>SpringMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
Block URLs containing '/' in all requests, such as springmvc/**/* URLs
3, the establishment of springmvc-servlet.xml documents
<?xml version= "1.0" encoding= "UTF-8"?> <beans "xmlns=" 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" xmlns:mvc= "Http://www.springframework.org/schema/mvc" xsi: schemalocation= "Http://www.springframework.org/schema/beans Http://www.springframework.org/schema/beans/spri Ng-beans-3.0.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/s Pring-context-3.0.xsd Http://www.springframework.org/schema/mvc Http://www.springframework.org/schema/mvc/spri Ng-mvc-3.0.xsd "> <!--the default scan package path--> <context:component-scan base-package=" * "/> <!--add annotation driver-- > <mvc:annotation-driven/> <!--defines the prefix--> <bean id= "Viewresolver" class= "Org.springframewor" for a jump file
K.web.servlet.view.internalresourceviewresolver "><property name= "prefix" value= "/web-inf/views/"/> <property name= "suffix" value= ". jsp"/> </bean> &l T;/beans>
Prefix and suffix the string string returned in controller and find the appropriate location in the project
4. Establish Controller
Package Net.csdn.blog.springmvc.controller;
Import Org.springframework.stereotype.Controller;
Import Org.springframework.ui.Model;
Import org.springframework.web.bind.annotation.RequestMapping;
@Controller public
class Pagecontroller {
@RequestMapping ('/login ') public
String Login (model model) {
Model.addattribute ("MSG", "Controller--> Login");
return "login";
}
Put the key value in model, in the foreground can be directly used El, Jstl expression to remove
5. Establish login.jsp
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "
pageencoding=" UTF-8 "%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd" >
6. Verification Results
This article only records the process from scratch for later viewing.
Not to be continued ...
Note: Please indicate the source of reprint.