Source: http://download.csdn.net/detail/fhxmn14991/8600273
There are netizens to download the source code, can't run up. This could be because of a problem with Tomcat deployment, which causes the main page to be missing. You can create a Web project yourself and then copy the code in to run it. You can also find the deployment of Tomcat online, is deployed to the WebApps folder, very simple.
1, first download the Spring and Tiles3 jar package, screenshots such as
Under
2, create spring-mvc.xml under SRC Create com.config, and then put in the inside
<?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: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/ Spring-beans.xsd
Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
Http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd ">
<!--Search Package path--
<context:component-scan base-package= "Com.karluto" use-default-filters= "false" >
<context:include-filter type= "Annotation" expression= "Org.springframework.stereotype.Controller"/>
</context:component-scan>
<!--Specify the system to find the controller path--
<mvc:annotation-driven/>
<!--access to static resources (Js/image)--
<mvc:resources location= "/web-jc/" mapping= "/js/**"/>
<!--definition Tiles View Resolver--
<bean id= "Tilesviewresolver" class= "Org.springframework.web.servlet.view.UrlBasedViewResolver" >
<property name= "Viewclass" >
<value>org.springframework.web.servlet.view.tiles3.TilesView</value>
</property>
</bean>
<bean id= "Tilesconfigurer" class= "Org.springframework.web.servlet.view.tiles3.TilesConfigurer" >
<property name= "Definitions" >
<list>
<value>/WEB-INF/tiles.xml</value>
</list>
</property>
</bean>
<bean id= "Viewresolver" class= "Org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name= "prefix" value= "/web-inf/jsp/" ></property>
<property name= "suffix" value= ". JSP" ></property>
</bean>
</beans>
3, Tiles.xml placed under the Web-inf, with Web. XML Unified Directory
<?xml version= "1.0" encoding= "UTF-8"?>
<! DOCTYPE tiles-definitions Public "-//apache software foundation//dtd tiles Configuration 3.0//en" "/http Tiles.apache.org/dtds/tiles-config_3_0.dtd ">
<tiles-definitions>
<definition name= "default.list" template= "/web-inf/jsp/template/list.jsp" >
<put-attribute name= "left" value= "/web-inf/jsp/template/left.jsp"/>
<put-attribute name= "main" value= "/web-inf/jsp/template/main.jsp"/>
</definition>
<definition name= "*.*ist" extends= "Default.list" >
<put-attribute name= "main" value= "/web-inf/jsp/karluto/{1}/{1}_{2}ist.jsp"/>
</definition>
<definition name= "* *" template= "/web-inf/jsp/template/error.jsp" >
</definition>
</tiles-definitions>
I'm using a wildcard, a lot of simplicity here.
4. Configure Web. xml
<?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_2_5.xsd" id= "Webapp_ ID "version=" 2.5 ">
<display-name>universal</display-name>
<servlet>
<servlet-name>spring-mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:com/config/spring-mvc.xml</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-mvc</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
<filter>
<filter-name>utf8-encoding</filter-name>
<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>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>utf8-encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
5, then create the Jsp/template folder under Web-inf, put the template page inside.
6, Useraction (Controller) placed under the com.karluto.action under the SRC
Package com.karluto.action;
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Org.springframework.web.servlet.ModelAndView;
@Controller
@RequestMapping ("/user")
public class Useraction {
@RequestMapping ("/default")
Public Modelandview indexlist () {
Modelandview Mav = new Modelandview ();
Mav.setviewname ("Default.list");
return MAV;
}
@RequestMapping ("/userlist")
Public Modelandview userlist () {
Modelandview Mav = new Modelandview ();
Mav.setviewname ("User.list");
return MAV;
}
}
6, finished, input http://localhost:8080/karluto/user/default.action