spring mvc web.xml dispatcher-servlet.xml配置
2016-08-28 14:24
337 查看
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" 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">
<display-name>edu</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!--spring-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>CharacterEncodingFilter</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>
<!--springmvc-->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
dispatcher-servlet.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"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<context:annotation-config/>
<!--支持json转换器-->
<mvc:annotation-driven>
<!-- 解决返回String时乱码-->
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- 配置直接转发的页面不用开发控制器-->
<mvc:view-controller path="/admin" view-name="/admin/admin"/>
<mvc:view-controller path="/regeist" view-name="/regeist"/>
<context:component-scan base-package="cn.*" />
<mvc:resources location="/file/" mapping="/file/**" />
<mvc:resources location="/js/" mapping="/js/**" />
<mvc:resources location="/css/" mapping="/css/**" />
<mvc:resources location="/images/" mapping="/images/**" />
<mvc:resources location="/easyui/" mapping="/easyui/**" />
<mvc:resources location="/bootstrap/" mapping="/bootstrap/**" />
<mvc:resources location="/Flat-UI/" mapping="/Flat-UI/**" />
<mvc:resources location="/uploadify/" mapping="/uploadify/**" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" 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">
<display-name>edu</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<!--spring-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>CharacterEncodingFilter</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>
<!--springmvc-->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
dispatcher-servlet.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"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<bean class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping"/>
<context:annotation-config/>
<!--支持json转换器-->
<mvc:annotation-driven>
<!-- 解决返回String时乱码-->
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/plain;charset=UTF-8</value>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<!-- 配置直接转发的页面不用开发控制器-->
<mvc:view-controller path="/admin" view-name="/admin/admin"/>
<mvc:view-controller path="/regeist" view-name="/regeist"/>
<context:component-scan base-package="cn.*" />
<mvc:resources location="/file/" mapping="/file/**" />
<mvc:resources location="/js/" mapping="/js/**" />
<mvc:resources location="/css/" mapping="/css/**" />
<mvc:resources location="/images/" mapping="/images/**" />
<mvc:resources location="/easyui/" mapping="/easyui/**" />
<mvc:resources location="/bootstrap/" mapping="/bootstrap/**" />
<mvc:resources location="/Flat-UI/" mapping="/Flat-UI/**" />
<mvc:resources location="/uploadify/" mapping="/uploadify/**" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/"
p:suffix=".jsp" />
</beans>
相关文章推荐
- springMVC的web.xml配置DispatcherServlet中Allocate exception for servlet DispatcherServlet异常处理
- Spring MVC 配置文件dispatcher-servlet.xml 文件详解
- SpringMVC 4.2.2 - Web.xml,Dispatcher-Servlet及ApplicationContext配置笔记
- Spring MVC 配置文件dispatcher-servlet.xml 文件详解
- 0077 web.xml中配置Spring MVC时,Servlet-name上报Servlet should have a mapping的错误
- 使用spring web.xml里的配置 - 请求处理器DispatcherServlet
- 使用spring web.xml里的配置 - 请求处理器DispatcherServlet
- Spring MVC 配置文件dispatcher-servlet.xml 文件详解
- 使用spring web.xml里的配置 - 请求处理器DispatcherServlet
- 在搭建Spring框架时,web.xml文件的配置之DispatcherServlet&ContextLoaderListener
- Spring Mvc 配置web.xml中的servlet-mapping时遇到的问题
- 关于Spring MVC的详细步骤(包括web.xml;applicationContext.xml;dispatcher-servlet.xml)
- spring mvc框架 web.xml配置文件 Could not open ServletContext resource [/WEB-INF/classes/spring-servlet.xml] 错误
- spring mvc 配置web.xml servlet.xml文件配置以及出现异常的解决方案
- 备忘:在web.xml中使用org.springframework.js.resource.ResourceServlet的配置对静态资源的访问
- servlet中配置文件web.xml中的参数context-param和init-param
- SERVLET配置到WEB.XML中
- servlet中web.xml配置详解
- web.xml文件中配置(servlet, spring, filter, listenr)的加载顺序研究
- Java Web 应用web.xml配置 --Servlet映射配置