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


相关推荐

  • IDEA连接mysql8数据库的方法以及遇上时区乱码的情况

    IDEA连接mysql8数据库的方法以及遇上时区乱码的情况

    2021年3月12日
    162
  • layoutSubviews的使用

    layoutSubviews的使用-(void)layoutSubviews{ }layoutSubviews是对subviews的重新布局以下情况会被调用1.直接调用layoutSubviews.如:[selflayoutSubviews];2.用addSubview添加视图时会触发3.滚动UIScrollView时会触发4.旋转屏幕的时候会触发父视图的layoutSu

    2022年7月15日
    18
  • java最长递增子序列_JAVA最长递增子序列「建议收藏」

    java最长递增子序列_JAVA最长递增子序列「建议收藏」问题描述LIS(LongestIncreasingSubsequence,最长递增子序列):给出一个序列a1,a2,a3,a4,a5,a6,a7…an,求它的一个子序列(设为s1,s2,…sn),使得这个子序列满足这样的性质,s1最长递增子序列实例分析17359481最长递增子序列算法设计设b[i]是在a[i]为单调递增子序列最后一个元素时,所得最长单调递增…

    2022年6月11日
    31
  • verycd下载办法_flac格式用什么播放器

    verycd下载办法_flac格式用什么播放器VeryCD的下载服务昨天晚上停掉了,和电影、剧集并列VeryCD三大板块的音乐从它的主页面上彻底抹掉了,如果不是这一年来VeryCD着力开拓了在线视频和类SNS服务的话,电影和剧集想来在昨晚也就一齐倒掉了。  VeryCD的命运其实在09年底BTchina被关掉的时候就能想象得到了,从那时起,VeryCD也就加快了转型的速度,面上的转型是“去盗版化”,除了SNS和在线播放业务外,这一年可

    2022年8月10日
    8
  • 【C/C++】C语言特性总结

    【C/C++】C语言特性总结已经有大约半年的时间没有碰C语言了,当时学习的时候记录了很多的笔记,但是都是特别混乱,后悔那个时候,不懂得写博客,这里凭借记忆和零零散散的笔记记录,尝试系统性地复习一下C语言。之前都是在Windows环境下学习,这次把重心放在Linux环境下,这次的复习源于基础,但是要高于基础。文章目录工具gcc编译器VS2019C语言编译过程C语言代码主体必要内容C语言数据类型关键字常量变量进制表示s…

    2022年6月21日
    17
  • git push到远程指定分支(git拉取指定分支代码)

    一、pull操作1、将远程指定分支拉取到本地指定分支上:gitpull&lt;远程仓库名&gt;&lt;远程分支名&gt;:&lt;本地分支名&gt;2、将远程指定分支拉取到本地当前分支上:gitpull&lt;远程仓库名&gt;&lt;远程分支名&gt;3、将与本地当前分支同名的远程分支拉取到本地当前分支上gitpull&lt;远程仓库名&…

    2022年4月18日
    4.5K

发表回复

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

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