springmvc配置文件

<?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:tx=”http://www.springframework.org/schema/tx” 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.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd “>

<!– 掃描controller處理類.爲了創建對象. –> <context:component-scan base-package=”cn.bdqn.controller”></context:component-scan> <!– 支持映射器的註解使用. –> <mvc:annotation-driven></mvc:annotation-driven>

<!– 配置視圖解析器 –> <bean class=”org.springframework.web.servlet.view.InternalResourceViewResolver”> <property name =”prefix” value=”/” /> <property name = “suffix” value=”.jsp” /> </bean>

<!– 靜態資源的配置: 可直接設置其WEB-INF外的資源訪問. 不支持內部資源訪問.因爲此配置將進行的是重定向的形式進行資源訪問的.–> <mvc:resources location=”/resource/js/” mapping=”/resource/js/**”></mvc:resources> <mvc:resources location=”/resource/css/” mapping=”/resource/css/**”></mvc:resources> <mvc:resources location=”/resource/img/” mapping=”/resource/img/**”></mvc:resources>

<!– 攔截器配置 –> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path=”/**”/> <bean class=”cn.bdqn.utils.LoginInterceptor”></bean> </mvc:interceptor> </mvc:interceptors>

<!– 配置錯誤處理器: –> <bean id=”handlerExceptionResolver” class=”cn.bdqn.utils.MyExceptionResolver”></bean>

<!– 配置上傳解析器: –> <bean id=”multipartResolver” class=”org.springframework.web.multipart.commons.CommonsMultipartResolver”> <!– 配置上傳限制大小: 2M–> <property name=”maxUploadSize”> <value>2097152</value> </property> </bean> </beans>

以下是web.xml配置

<?xml version=”1.0″ encoding=”UTF-8″?> <web-app version=”2.5″ xmlns=”http://java.sun.com/xml/ns/javaee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd”>

<!– 配置重要組件: DispatcherServlet. 爲了使用SpringMVC處理用戶請求. 同時,讓此組件在加載的同時,初始化controller. –> <servlet>

    <servlet-name>springmvc1</servlet-name>

    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    <init-param>

       <param-name>contextConfigLocation</param-name>

       <param-value>classpath:spring-mvc.xml</param-value>

    </init-param>

</servlet>

<!– /* : 攔截所有成員請求,將*號匹配的成員去尋找映射. 如果響應的是jsp或者頁面請求js等靜態資源都會被攔截. *.action : 將提取*成員內容,去 匹配尋找映射. 只攔截後綴名爲action的請求. /:攔截所有成員,但是全部默認放行響應結果中的jsp.不用匹配任何內容. 如果jsp頁面引入js等靜態資源.此時需要在spring容器中單獨配置靜態資源的訪問設置. –>

<servlet-mapping>

      <servlet-name>springmvc1</servlet-name>

      <url-pattern>/</url-pattern>

</servlet-mapping>

<welcome-file-list>

      <welcome-file>index.jsp</welcome-file>

</welcome-file-list>

</web-app>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章