一、web.xml文件介绍

  • The web.xml file contains several elements that are required for a Facelets application. All of the following are created automatically when you use NetBeans IDE to create an application.
  • web.xml文件的作用

web.xml主要用来配置Filter、Listener、Servlet等。但是要说明的是web.xml并不是必须的,一个web工程可以没有web.xml文件。

  • WEB容器的加载过程

WEB容器的加载顺序是:

ServletContext -> context-param -> listener -> filter -> servlet。在web.xml文件中最好按照这种顺序配置这些元素,以兼容较低版本的Tomcat。

  • WEB容器的启动过程

WEB容器启动时,加载过程顺序如下:

    1. 启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取<listener>和<context-param>两个结点。
    2. 紧急着,容创建一个ServletContext(servlet上下文),这个web项目的所有部分都将共享这个上下文。
    3. 容器将<context-param>转换为键值对,并交给servletContext。
    4. 容器创建<listener>中的类实例,创建监听器。

二、web.xml of hello1 analysis

• xml文档第一行的声明和它的文档元素描述信息。

<?xml version="1.0" encoding="UTF-8"?>
  • 表示文档符合xml1.0规范,文档字符编码默认为“UTF-8”

• Servlet 3.1 deployment descriptor:

<web-app version="3.1"
     xmlns="http://xmlns.jcp.org/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">     ...
</web-app>
  • Java EE 7 XML schema, namespace is http://xmlns.jcp.org/xml/ns/javaee/
  • web-app是web.xml文档的根元素
  • xmlns是XML NameSpace的缩写
  • xmls(:xxx)="yyy"这是xml引入名称空间的语法格式,式中,“xxx”表示引入名臣空间的前缀名,可以指定(如“xsi”),也可不指定(使用默认),“yyy”表示该名称空间的名称,形式上为一个URL。
  • xsi名称空间下有很多较为重要的属性,其中一个就是xsi:schemaLocation,它的作用是引入XML Schema文档,对xml文档的元素进行内容约束。它包含了两个URL,这两个URL之间用空白符或者换行符进行分割。第一个URL是名称空间的名称,第二个URL是文档的位置。那么,这句的作用是引入一个名称空间为http://xmlns.jcp.org/xml/ns/javaee、文档位置为http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd的XML Schema文档。也可参阅Eclipse XML文件模板中给出的XML文件引入Schema文档的语法格式:
    xsi:schemaLocation="{namespace} {location}

• A context parameter specifying the project stage:

<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value></context-param>
  • A context parameter provides configuration information needed by a web application. An application can define its own context parameters. In addition, JavaServer Faces technology and Java Servlet technology define context parameters that an application can use.
  • 声明应用范围内的初始化参数。它用于向 ServletContext提供键值对,即应用程序上下文信息。我们的listener, filter等在初始化时会用到这些上下文中的信息。
  • 在servlet里面可以通过getServletContext().getInitParameter("context/param")得到。

• A servelt element and its servlet-mapping element specifying the FacesServlet. All files with the .xhtml suffix will be matched:

<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
  • <servlet> 用来声明一个servlet的数据,主要有以下子元素:
  • <servlet-name> 指定servlet的名称
  • <servlet-class> 指定servlet的类名称
  • <jsp-file> 指定web站台中的某个JSP网页的完整路径
  • <init-param> 用来定义参数,可有多个init-param。
  • <load-on-startup> 当值为正数或零时,从小到大加载。否则第一次访问时加载。
  • <servlet-mapping> 用来定义servlet所对应的URL,包含两个子元素
  • <servlet-name> 指定servlet的名称
  • <url-pattern> 指定servlet所对应的URL

• 会话超时配置:

<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>

• A welcome-file-list element specifying the location of the landing page:

<welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
</welcome-file-list>

参考:(https://javaee.github.io/tutorial/webapp003.html#GJWTV)

   (https://www.jianshu.com/p/0e53eff3b920)

   (https://www.cnblogs.com/LiZhiW/p/4313844.html)

Analysis of Web.xml in Hello1 project的更多相关文章

  1. Analysis of Web.xml in Hello1project

    一下是hello1  web inf 里的  web.xml <?xml version="1.0" encoding="UTF-8"?><w ...

  2. analyse web.xml of hello1

    web.xml注释分析: 补充: 一.XML文档的xmlns.xmlns:xsi和xsi:schemaLocation (参考博客:https://www.cnblogs.com/osttwz/p/6 ...

  3. web.xml的简单解释以及Hello1中web.xml的简单分析

    一.web.xml的加载过程 ①当我们启动一个WEB项目容器时,容器包括(JBoss,Tomcat等).首先会去读取web.xml配置文件里的配置,当这一步骤没有出错并且完成之后,项目才能正常的被启动 ...

  4. maven项目提示web.xml is missing或红色感叹号

    1.web.xml is missing and <failOnMissingWebXml> is set to true 提示信息应该能看懂.也就是缺少了web.xml文件,<fa ...

  5. pom.xml出现web.xml is missing and <failOnMissingWebXml> is set to true解决方案

    提示信息应该能看懂.也就是缺少了web.xml文件,<failOnMissingWebXml>被设置成true了. 搜索了一下,Stack Overflow上的答案解决了问题,分享一下. ...

  6. Descriptors;Hello1 project中的Web.xml

    Deployment Descriptors(描述符)是一个xml文件,用来描述如何部署一个模块或者应用(根据描述符中定义的配置和容器选项).举例来说,一个EJB的部署描述符会向EJB容器传递如何管理 ...

  7. 新建web project不自动生成web.xml解决方案

    一步一步建立Web Project ,第3步会有 “Generate Web.xml deployment descriptor”,默认没勾选,勾上就行了

  8. 分析hello1项目里面的web.xml

    在example目录下的web\jsf\hello1\target\hello1\WEB-INF路径里可以找到hello1的web.xml <?xml version="1.0&quo ...

  9. web.xml hello1代码分析

    在“Web页”节点下,展开WEB-INF节点,然后双击web.xml文件进行查看. 上下文参数提供Web应用程序所需的配置信息.应用程序可以定义自己的上下文参数.此外,JavaServer Faces ...

随机推荐

  1. Jupyter Notebook 的安装使用以及 tree 路径变更

    由于最近开始学习 Python,进而接触到一个十分强大的交互式编辑器 — Jupyter Notebook,用起来也非常顺手,于是记录一下相关的使用过程. 一.安装 Python: ①首先前往 pyt ...

  2. 联网请求数据:Android篇

    这篇文章主要回顾之前的MYangtzeu App教程的联网请求方法和json解析套路,主要目的是实现左侧菜单数据的联网获取. 1.先上请求地址实体类Constants.java package com ...

  3. 【nginx】配置

    server { listen 80; server_name hocalhost; location / { root /usr/share/nginx/html; index index.html ...

  4. UOJ #310「UNR #2」黎明前的巧克力

    神仙题啊... UOJ #310 题意 将原集合划分成$ A,B,C$三部分,要求满足$ A,B$不全为空且$ A$的异或和等于$ B$的异或和 求方案数 集合大小 $n\leq 10^6$ 值域$v ...

  5. 组件或者dom的特殊属性

    key:用在 Vue 的虚拟 DOM 算法,在新旧 nodes 对比时辨识 VNodes. 常用姿势: 1.结合 v-for,有相同父元素的子元素必须有唯一key. <ul> <li ...

  6. React 轮播图实现

    接到项目, 用react和material-ui实现轮播图. 搜索了一些方法参考, 不论语言/框架的使用,大体上分为两种思路 超宽列表实现法 在原生JS或者JQuery中,轮播图的实现一般是这样子的 ...

  7. safari下载中文文件名乱码

    原因:响应头设置content-disposition,主要遵循 RFC 5987标准. response.setHeader("content-disposition",&quo ...

  8. 019_UT、IT、ST、UAT

    软件开发中的完成测试环境所包括的环节包括:UT.IT.ST.UAT UT = Unit Test 单元测试 IT = System Integration Test 集成测试 ST = System ...

  9. springboot动态多数据源

    参考文章:https://www.cnblogs.com/hehehaha/p/6147096.html 前言 目标是springboot工程支持多个MySQL数据源,在代码层面上,同一个SQL(Ma ...

  10. 【java】java基本用法记录

    java用法总结 计时 long startTime = System.nanoTime(); solution.process(inputFile); long endTime = System.n ...