Web.xml配置说明

Web.xml配置说明1. web.xml配置详解:     <web-app> <!–指定WEB应用的名字–> <display-name>MyWeb</display-name> <!–WEB应用描述信息–> <description>MyWeb demo</description&gt

大家好,又见面了,我是你们的朋友全栈君。

1. web.xml配置详解:

     

<web-app>
    <!--指定WEB应用的名字-->
    <display-name>MyWeb</display-name>

    <!--WEB应用描述信息-->
    <description>MyWeb demo</description>


    <!--web的初始化参数,通过ServletContextEvent.getServletContext().getInitParameter("field")获得value的值(ServletContextEvent通过listener获得)-->
    <context-param>
        <param-name>contextConfigLocation</para-name>
        <param-value>classpath:applicationContext.xml</param-value>
        <description>web的ApplicationContext上下问文件配置</description>
    </context-param>

    <!--filter 和filter-mapping 必须是成对出现-->

    <!--拦截/*的路径,执行CharacterEncodingFilter的父类的OncePerRequestFilter的doFilter(doFilter中调用doFilterInternal方法,设置request和response的编码方式设置为UTF-8)-->
    <filter>
        <filter-name>utf8-encoding</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>utf8-encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>


    <!--servlet 监听配置,项目启动时执行contextInitialized(ServletContextEvent servletContextEvent)方法,项目停止时执行contextDestroyed(ServletContextEvent event)-->
    <listener>
        <listerner-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>


    <!--servlet和servlet-mapping是成对出现的,服务启动时,执行HttpServlet.init(ServletConfig config)方法,当用户请求/myservlet/*路径时,执行HttpServlet.service(HttpServletRequest req, HttpServletResponse resp)方法-->
    <servlet>
        <servlet-name>myservlet</servlet-name>
        <servlet-class>javax.servlet.http.HttpServlet</servlet-class>
        <init-param>
            <param-name>paramField</param-name>
            <param-value>paramValue</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>myservlet</servlet-name>
        <url-pattern>/myservlet/*</url-pattern>
    </servlet-mapping>

    <!--会话超时时间设置,单位是分钟-->
    <session-config>
        <session-timeout>10</session-timeout>
    </session-config>

    <!--mime-mapping元素将mime类型映射到扩展名, 用于规定下载格式-->
    <mime-mapping>
        <extension>htm</extension>
        <mime-type>text/html</mime-type>
    </mime-mapping>

    <mime-mapping>
        <extension>pdf</extension>
        <mime-type>application/pdf</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>doc</extension>
        <mime-type>application/msword</mime-type>
    </mime-mapping>
    <mime-mapping>
        <extension>xls</extension>
        <mime-type>application/msexcel</mime-type>
    </mime-mapping>


    <!--指定Web项目的欢迎页面-->
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

    <!--当请求发生404错误时,跳转到404error.jsp页面-->
    <error-page>
        <error-code>404</error-code>
        <location>/404error.jsp</location>
    </error-page>

    <!--当Web服务发生java.lang.NullException异常时,跳转到nullerror.jsp页面-->
    <error-page>
        <exception-type>java.lang.NullException</exception-type>
        <location>/nullerror.jsp</location>
    </error-page>

    <!--对tag库文件名称。前端JSP可以通过<%@ taglib uri="http://jakarta.apache.org/tomcat/debug-taglib" prefix="myTag"%>配置使用tag库-->
    <taglib>
        <taglib-uri>http://jakarta.apache.org/tomcat/debug-taglib</taglib-uri>
        <taglib-location>/WEB-INF/tld/taglib.tld</taglib-location>
    </taglib>

    <!--配置资源相关的管理对象,可通过new InitialContext().lookup()获得值-->
    <resource-env-ref>
        <resource-env-ref-name>jms/StockQueue</resource-env-ref-name>
    </resource-env-ref>

    <!--设置factory的外部资源-->
    <resource-ref>
        <description>java JDBC DataSource factory</description>
        <res-ref-name>jdbc/java_db</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>dataManager</res-auth>
    </resource-ref>

    <security-constraint></security-constraint>
    <login-config></login-config>
    <security-role></security-role>
    <env-entry></env-entry>
</web-app>

 

 

 

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/149544.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • python中range的三种用法

    python中range的三种用法range 函数可以创建一个整数列表 一般用在 for 循环中 1 range stop 0 stop 1 这个代表起始值是零 终止值是 stop 1 步长默认为 1forindexinr 5 print indexis d index 输出是 indexis 0 indexis 1 indexis 2 indexis 3 indexis 4 等价的 C 写法如下 for inti 0 i lt 5 i

    2025年6月30日
    3
  • nginx实现https网站设置(SSL证书生成配置)

    nginx实现https网站设置(SSL证书生成配置)

    2021年6月2日
    91
  • Log4net中ConversionPattern的代码解释[通俗易懂]

    Log4net中ConversionPattern的代码解释[通俗易懂]      layout type=”log4net.Layout.PatternLayout”>        param name=”Header” value=”———————–header————————–” />        param name=”Footer” value=”——————–

    2022年8月22日
    12
  • ARM指令集

    ARM指令集

    2021年8月23日
    54
  • 数据库读写分离的优点

    数据库读写分离的优点读写分离的优点在传统的编码的过程中 往往是在数据库由于抗不住服务器的压力 或者是 IO 达到瓶颈之后 必须用到分库的时候 才采用读写分离的方案 个人认为读写分离的作用远不止此 今天 根据博主我作为程序猿的经验 来和大家分享一下数据库读写分离带来的优点 一 读写分离带来的扩展性更强在我们编码的过程中 随着项目的业务增多 必然会致使业务接口越来越多 接口越多 带来的维护成本就相对较高 如果没有对应文档的记录 即使作为研发人员的我们 都很大可能忘记那些接口有那些功能 那些接口被调用过多少次 以上就很可能带来一

    2025年8月26日
    4
  • 通读音_Android API

    通读音_Android API所谓工欲善其事,必先利其器,所以通读了cheerio的API,顺便翻译了一遍,有些地方因为知道的比较少,不知道什么意思,保留了英文,希望各位不吝告诉我,然后一起把这个翻译完成。###cheerio为服务器特别定制的,快速、灵活、实施的jQuery核心实现.###Introduction将HTML告诉你的服务器varcheerio=require(‘cheerio’),$

    2025年6月21日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号