springmvc开发xml配置文件内容

文章转自点击打开链接

1.springmvc的配置文件springmvc-config.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:context="http://www.springframework.org/schema/context"  
    xmlns:mvc="http://www.springframework.org/schema/mvc"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans   
                        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd  
                        http://www.springframework.org/schema/context   
                        http://www.springframework.org/schema/context/spring-context-4.3.xsd  
                        http://www.springframework.org/schema/mvc   
                        http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">  
    <context:component-scan base-package="dreamyy.top.hrm.controller"></context:component-scan>  
    <!-- 设置默认配置文件 -->  
    <mvc:annotation-driven/>  
    <!-- 使用默认的servlet来响应静态文件 -->  
    <mvc:default-servlet-handler/>  
    <!-- 定义springmvc拦截器 -->  
    <mvc:interceptors>  
        <mvc:interceptor>  
            <mvc:mapping path="/*"/>  
            <bean class="dreamyy.top.hrm.interceptor.AuthorizedInterceptor"></bean>  
        </mvc:interceptor>  
    </mvc:interceptors>  
    <!--视图解析器 -->  
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">  
        <!-- 前缀 -->  
        <property name="prefix">  
            <value>/WEB-INF/jsp/</value>  
        </property>  
        <!-- 后缀 -->  
        <property name="suffix">  
            <value>.jsp</value>  
        </property>  
    </bean>  
    <!-- 配置文件上传下载 -->  
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">  
        <!-- 文件上传大小上限  大小为字节(10M) -->  
        <property name="maxUploadSize">  
            <value>10485760</value>  
        </property>  
        <property name="defaultEncoding">  
            <value>UTF-8</value>  
        </property>  
    </bean>  
</beans>  
2. web.xml
<?xml version="1.0" encoding="UTF-8"?>  
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">  
  <display-name>hrmapp</display-name>  
  <welcome-file-list>  
    <welcome-file>index.html</welcome-file>  
    <welcome-file>index.htm</welcome-file>  
    <welcome-file>index.jsp</welcome-file>  
    <welcome-file>default.html</welcome-file>  
    <welcome-file>default.htm</welcome-file>  
    <welcome-file>default.jsp</welcome-file>  
  </welcome-file-list>  
  <listener>  
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  </listener>  
  <context-param>  
    <param-name>contextConfigLocation</param-name>  
    <param-value>/WEB-INF/applicationContext.xml</param-value>  
  </context-param>  
  <servlet>  
    <servlet-name>springmvc</servlet-name>  
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
    <init-param>  
      <param-name>contextConfigLocation</param-name>  
      <param-value>/WEB-INF/springmvc-config.xml</param-value>  
    </init-param>  
    <load-on-startup>1</load-on-startup>  
  </servlet>  
  <servlet-mapping>  
    <servlet-name>springmvc</servlet-name>  
    <url-pattern>/</url-pattern>  
  </servlet-mapping>  
  <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>  
  </filter>  
  <filter-mapping>  
    <filter-name>characterEncodingFilter</filter-name>  
    <url-pattern>/*</url-pattern>  
  </filter-mapping>  
  <jsp-config>  
    <jsp-property-group>  
      <url-pattern>*.jsp</url-pattern>  
      <el-ignored>false</el-ignored>  
      <scripting-invalid>true</scripting-invalid>  
      <include-prelude>/WEB-INF/jsp/taglib.jsp</include-prelude>  
    </jsp-property-group>  
  </jsp-config>  
  <error-page>  
    <error-code>404</error-code>  
    <location>/404.html</location>  
  </error-page>  
</web-app>  




猜你喜欢

转载自blog.csdn.net/gardenpalace/article/details/78608669