Analysis of Web.xml in Hello1 project

一、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容器启动时,加载过程顺序如下:
启动一个WEB项目的时候,WEB容器会去读取它的配置文件web.xml,读取和两个结点。
紧急着,容创建一个ServletContext(servlet上下文),这个web项目的所有部分都将共享这个上下文。
容器将转换为键值对,并交给servletContext。
容器创建中的类实例,创建监听器。

二、web.xml of hello1 analysis
• xml文档第一行的声明和它的文档元素描述信息。

<?xml version="1.0" encoding="UTF-8"?>

表示文档符合xml1.0规范,文档字符编码默认为“UTF-8”

• Servlet 3.1 deployment descriptor:



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:

javax.faces.PROJECT_STAGE
Development

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:

Faces Servlet
javax.faces.webapp.FacesServlet
1


Faces Servlet
*.xhtml

用来声明一个servlet的数据,主要有以下子元素:
指定servlet的名称
指定servlet的类名称
指定web站台中的某个JSP网页的完整路径
用来定义参数,可有多个init-param。
当值为正数或零时,从小到大加载。否则第一次访问时加载。
用来定义servlet所对应的URL,包含两个子元素
指定servlet的名称
指定servlet所对应的URL

• 会话超时配置:


30

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

index.xhtml

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值