关闭

spring mvc web.xml dispatcher-servlet.xml配置

标签: spring mvc xml 配置
99人阅读 评论(0) 收藏 举报
分类:

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>



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:12856次
    • 积分:409
    • 等级:
    • 排名:千里之外
    • 原创:29篇
    • 转载:2篇
    • 译文:0篇
    • 评论:0条