Analysis of Web.xml in Hello1 project
一、web.xml文件介绍
- The
web.xmlfile 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,读取<listener>和<context-param>两个结点。
- 紧急着,容创建一个ServletContext(servlet上下文),这个web项目的所有部分都将共享这个上下文。
- 容器将<context-param>转换为键值对,并交给servletContext。
- 容器创建<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的更多相关文章
- Analysis of Web.xml in Hello1project
一下是hello1 web inf 里的 web.xml <?xml version="1.0" encoding="UTF-8"?><w ...
- analyse web.xml of hello1
web.xml注释分析: 补充: 一.XML文档的xmlns.xmlns:xsi和xsi:schemaLocation (参考博客:https://www.cnblogs.com/osttwz/p/6 ...
- web.xml的简单解释以及Hello1中web.xml的简单分析
一.web.xml的加载过程 ①当我们启动一个WEB项目容器时,容器包括(JBoss,Tomcat等).首先会去读取web.xml配置文件里的配置,当这一步骤没有出错并且完成之后,项目才能正常的被启动 ...
- maven项目提示web.xml is missing或红色感叹号
1.web.xml is missing and <failOnMissingWebXml> is set to true 提示信息应该能看懂.也就是缺少了web.xml文件,<fa ...
- pom.xml出现web.xml is missing and <failOnMissingWebXml> is set to true解决方案
提示信息应该能看懂.也就是缺少了web.xml文件,<failOnMissingWebXml>被设置成true了. 搜索了一下,Stack Overflow上的答案解决了问题,分享一下. ...
- Descriptors;Hello1 project中的Web.xml
Deployment Descriptors(描述符)是一个xml文件,用来描述如何部署一个模块或者应用(根据描述符中定义的配置和容器选项).举例来说,一个EJB的部署描述符会向EJB容器传递如何管理 ...
- 新建web project不自动生成web.xml解决方案
一步一步建立Web Project ,第3步会有 “Generate Web.xml deployment descriptor”,默认没勾选,勾上就行了
- 分析hello1项目里面的web.xml
在example目录下的web\jsf\hello1\target\hello1\WEB-INF路径里可以找到hello1的web.xml <?xml version="1.0&quo ...
- web.xml hello1代码分析
在“Web页”节点下,展开WEB-INF节点,然后双击web.xml文件进行查看. 上下文参数提供Web应用程序所需的配置信息.应用程序可以定义自己的上下文参数.此外,JavaServer Faces ...
随机推荐
- Oracle DB 总结(SQL)
--SQL结构查询语言 数据库定义语言(DDL)用于建立.删除和修改数据库对象 CREATE ALTER DROP TRUNCATE 数据库操纵语言(DML)用于改变数据库表中的数据 INSERT U ...
- Visual Studio Shortcuts
https://docs.google.com/file/d/0Bw8aEjCQGEquMjRaWFBKUUtuRE0/edit
- 中文 Tex
\documentclass{article} \usepackage{ctex} \begin{document} 中文English \[E = m c^2\] \end{document} \d ...
- 初识springboot(傻瓜式教程)
初识springboot(傻瓜式教程) 项目所需的版本 IDEA 2018 maven 3.x jdk-1.8 IDEA创建spring-boot项目(maven方法) 1.创建一个maven工程 点 ...
- Theano.tensor.round函数学习,同时解决输出Elemwise{xxx,no_inplace}.0的问题
1. 出现Elemwise{xxx,no_inplace}.0 这是因为没有定义theano.function所致,参考下面错误示范: y = np.random.normal(size=(2,2 ...
- Input子系统与多点触摸技术-3【转】
转自:https://blog.csdn.net/u012839187/article/details/77335941 版权声明:本文为博主原创文章,欢迎转载,转载请注明转载地址 https://b ...
- DotNet 资源大全(转)
awesome-dotnet 是由 quozd 发起和维护.内容包括:编译器.压缩.应用框架.应用模板.加密.数据库.反编译.IDE.日志.风格指南等. https://github.com/jo ...
- I - Beautiful People ZOJ - 2319 (二分法)
The most prestigious sports club in one city has exactly N members. Each of its members is strong an ...
- 使用element-ui遇到的各种小问题
一.Dialog对话框 1.在使用嵌套Dialog的时候,会出现遮罩层在内容的上方这种错乱情况 解决办法:http://element-cn.eleme.io/#/zh-CN/component/di ...
- iOS unity 互相调用加载高德地图时
需要增加 mapView.delegate = self 这是一种设计模式,有的人称为代理,有的人称为委托,比如有A,B两个控制器,由A可以push到B,B可以pop回A,现在有一种情况,A中有一个l ...