1 ,项目的文件路径先贴上来;
2,进入主题,web.xml配置
大家都知道代码如下
<!-- 配置前台页面 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/fep-servlet.xml
</param-value>
</context-param>
<!--可以是自定义的过滤器,或者不配置该过滤器,用spring自己提供的CharacterEncodingFilter过滤器-->
<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>com.***.rhm.busi.utils.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<!-- 分发器 配置, 找到对应的资源-->
<servlet>
<servlet-name>fep</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>fep</param-name>
<param-value>classpath*:fep-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>fep</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
下面配置 web.xml定义的需要加载的fep-servlet.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<!-- 配置文件加载 -->
<bean id="propertyConfigure" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
</list>
</property>
</bean>
<!-- HandlerMapping -->
<bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"/>
<!-- HandlerAdapter -->
<bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter"/>
<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/index.html">indexController</prop>
<prop key="/card.html">cardController</prop>
<prop key="/cardupdate.html">cardupdateController</prop>
<prop key="/cardsave.html">cardsaveController</prop>
<prop key="/qfwsave.html">qfwsaveController</prop>
<prop key="/ywfwsave.html">ywfwsaveController</prop>
</props>
</property>
</bean>
<import resource="hdc-spring-context.xml" />
<bean name="indexController" class="cn.wadata.hdc.fep.controller.TestController">
<property name="greeting" value="进入首页 "/>
</bean>
<!-- hcm引入 velocity -->
<!-- 解析velocity -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
<property name="exposeSpringMacroHelpers" value="true" />
<property name="requestContextAttribute" value="rc" />
<property name="suffix" value=".html" />
<property name="prefix" value="" />
<property name="dateToolAttribute" value="dateTool" />
<property name="numberToolAttribute" value="numberTool" />
<property name="exposeRequestAttributes" value="true" />
<property name="exposeSessionAttributes" value="true" />
<property name="contentType" value="text/html;charset=utf-8" />
</bean>
<!-- Spring+Velocity集成配置 -->
<bean id="velocityConfigurer"
class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/WEB-INF/views/" />
<property name="velocityProperties">
<props>
<prop key="input.encoding">utf-8</prop>
<prop key="output.encoding">utf-8</prop>
</props>
</property>
</bean>
<!-- 资源文件过滤 -->
<!-- <mvc:resources mapping="/css/**" location="/css/" />
<mvc:resources mapping="/js/**" location="/js/" />
<mvc:resources mapping="/images/**" location="/images/" />
<mvc:resources mapping="/flex/**" location="/flex/" />
<mvc:resources mapping="/dll/**" location="/dll/" />
<mvc:annotation-driven /> -->
</beans>
我把原文件直接贴出来了,资源文件过滤在spring2.0的是不支持的
为了以后能扩张 单独将bean放在不同的xml中
<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<!-- 控制页面跳转 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>WEB-INF/conf/application_fep.properties</value>
</property>
</bean>
<bean name="cardController" class="cn.wadata.hdc.fep.controller.CardController">
<property name="name" value="李四"/>
<property name="pwd" value="url"/>
</bean>
<bean name="cardupdateController" class="cn.wadata.hdc.fep.controller.CardupdateController">
<property name="message" value="跳转修改"/>
</bean>
<bean name="cardsaveController" class="cn.wadata.hdc.fep.controller.CardSaveController">
</bean>
<bean name="qfwsaveController" class="cn.wadata.hdc.fep.controller.QfwSaveController">
</bean>
<bean name="ywfwsaveController" class="cn.wadata.hdc.fep.controller.YwfwSaveController">
</bean>
</beans>
配置完这3个文件,就直接到Controller控制类了
public class TestController implements Controller{
private static final Logger logger =Logger.getLogger(TestController.class);
private String greeting;
public String getGreeting() {
return greeting;
}
public void setGreeting(String greeting) {
this.greeting = greeting;
}
/**
* @see org.springframework.web.servlet.mvc.Controller#handleRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public ModelAndView handleRequest(HttpServletRequest arg0,
HttpServletResponse arg1) throws Exception {
logger.info("进入controller");
return new ModelAndView("index","greeting",greeting);
}
}
这些弄完,那你就少一个index.html的页面啦
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<h1>欢迎你!!!</h1><h2>${greeting}</h2>
<button value=""> 跳转到功能页面</button>
<input type="button" value="跳转功能" onclick="goNext()"></input>
</body>
</html>