您的位置:首页 > 编程语言 > Java开发

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐