maven工程web层的web.xml配置文档内容

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了maven工程web层的web.xml配置文档内容相关的知识,希望对你有一定的参考价值。

下面是web层,web.xml配置文档里面需要配置的东西:

1、lo4j配置

2、读取spring文件配置

3、设计路径变量值

4、spring字符集过滤器

5、登陆过滤器

6、springMVC核心配置

7、session过期时间

8、错误页面跳转

 

以下是实例:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>bridgechart-web</display-name>

    <!-- log4j 配置 -->
    <context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:properties/log4j.properties</param-value>
    </context-param>
    <!-- load log4j -->
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    <!-- 读取spring配置文件 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:xml/spring.xml;
            classpath:xml/spring-mybatis.xml
            <!-- ;classpath:xml/spring-job.xml -->
        </param-value>
    </context-param>
    <!-- 设计路径变量值 -->
    <context-param>
        <param-name>webAppRootKey</param-name>
        <param-value>bridgechart-web.root</param-value>
    </context-param>
    <context-param>
        <param-name>log4jExposeWebAppRoot</param-name>
        <param-value>false</param-value>
    </context-param>
    <!-- Spring字符集过滤器 -->
    <filter>
        <filter-name>SpringEncodingFilter</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>
    <filter-mapping>
        <filter-name>SpringEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <!-- 登录过滤器 -->
    <filter>
        <filter-name>PagesFilter</filter-name>
        <filter-class>com.mmc.d4alc.controller.PagesFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>PagesFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- springMVC核心配置 -->
    <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:xml/spring-mvc.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>default</servlet-name>
        <url-pattern>*.mp4</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>
    
  
  <!-- session过期时间-->
  <session-config>
      <session-timeout>10</session-timeout>
  </session-config>
  
    <!-- 错误跳转页面 -->
    <error-page>
        <!-- 路径不正确 -->
        <error-code>404</error-code>
        <location>/view/common/404.jsp</location>
    </error-page>
    <error-page>
        <!-- 没有访问权限,访问被禁止 -->
        <error-code>405</error-code>
        <location>/view/common/405.jsp</location>
    </error-page>
    <error-page>
        <!-- 内部错误 -->
        <error-code>500</error-code>
        <location>/view/common/500.jsp</location>
    </error-page>
</web-app>

 

以上是关于maven工程web层的web.xml配置文档内容的主要内容,如果未能解决你的问题,请参考以下文章

maven工程web层的spring-mybatis配置文档

maven创建web工程Spring配置文件找不到问题解决方案

IDEA导入maven工程以及web.xml中spring配置文件文件加载不到的问题

maven之相关概念

idea+maven+Strtus2 之新建工程

基于dubbo的SOA项目改造