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)
全栈程序员-站长的头像全栈程序员-站长

相关推荐

  • JavaScript—-什么是纯函数

    JavaScript—-什么是纯函数定义简单来说,一个函数的返回结果只依赖于它的参数,并且在执行过程里面没有副作用,我们就把这个函数叫做纯函数。这么说肯定比较抽象,我们把它掰开来看:函数的返回结果只依赖于它的参数。函数执行过程里面没有副作用。consta=1constfoo=(b)=&gt;a+bfoo(2)//=&gt;3foo函数不是一个纯函数,因为它返回的结果依赖于外部变量…

    2022年10月23日
  • centos打开windows的ftp 无法显示内容 显示空白内容

    centos打开windows的ftp 无法显示内容 显示空白内容

    2021年8月24日
  • python读取excel单元格内容_python如何读取txt文件

    python读取excel单元格内容_python如何读取txt文件今天,跟大家谈一下用python计算Excel中的数据我们先学习读取Excel中的数据首先我们要安装xlrd库,在命令提示符(快捷键win+r)中输入:pipinstallxlrd下载完成xlrd库。首先呢,当然要先有一个Excel啦,如下:我们先仔细观察这个Excel,里面有2018、2017、2016的月收入来来来,跟着小哥哥一起月入3w!1、利用python读取Excel内容xrld库中的open_workbook函数可以打开Excel文件,并且返回一个代表打开Excel文

    2022年10月2日
  • 重定向和转发的区别及应用_重定向是什么意思

    重定向和转发的区别及应用_重定向是什么意思请求转发:客户首先发送一个请求到服务器端,服务器端发现匹配的servlet,并指定它去执行,当这个servlet执行完之后,它要调用getRequestDispacther()方法,把请求转发给指定的student_list.jsp,整个流程都是在服务器端完成的,而且是在同一个请求里面完成的,因此servlet和jsp共享的是同一个request,在servlet里面放的所有东西,在stude…

    2022年9月8日
  • python h5文件读取_python读取整个txt文件

    python h5文件读取_python读取整个txt文件这篇文章是一个工具类,用来辅助医学图像分割实战unet实现(二)4、数据存储这一小节的内容。文件:HDF5DatasetGenerator.py#-*-coding:utf-8-*-importh5pyimportosimportnumpyasnpclassHDF5DatasetGenerator:def__init__(self,…

    2022年9月3日
  • 【Unity3D 灵巧小知识点】 ☀️ | Unity中如何使用代码切换场景

    【Unity3D 灵巧小知识点】 ☀️ | Unity中如何使用代码切换场景Unity小科普老规矩,先介绍一下Unity的科普小知识:Unity是实时3D互动内容创作和运营平台。包括游戏开发、美术、建筑、汽车设计、影视在内的所有创作者,借助Unity将创意变成现实。Unity平台提供一整套完善的软件解决方案,可用于创作、运营和变现任何实时互动的2D和3D内容,支持平台包括手机、平板电脑、PC、游戏主机、增强现实和虚拟现实设备。也可以简单把Unity理解为一个游戏引擎,可以用来专业制作游戏!Unity小知识点学习Unity中如何使用代码切.

    2022年5月29日

发表回复

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

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