servlet生命周期及web.xml配置
来源:互联网 发布:js获取a标签href 编辑:程序博客网 时间:2024/06/05 21:06
Servlet工作原理
- 浏览器向web服务器发送http请求
- web服务器解析主机地址,解析webapps,解析资源名,向web.xml查询servlet位置
- web服务器创建HttpServletRequest对象,将http请求封装在里面
- web服务器创建HttpServletResponse对象
- 创建servlet实例,第一调用时执行init(),只执行一次,之后调用doGet()和doPost()方法
- HttpServlet调用doGet()和doPost()的HttpServletRequest的有关方法获取http请求
- HttpServlet调用doGet()和doPost()的HttpServletResponse的有关方法生成响应数据
- web服务器将HttpServletResponse对象分解为http请求
- 浏览器接收http请求
- destroy()方法也只调用一次,当reload,关闭tomcat或者关机等时
web.xml配置
<servlet> <servlet-name>Servlet名字</servlet-name> <servlet-class>此servlet全路径</servlet-class> <!-- 定义参数 --> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>vision</param-name> <param-value>1.0</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Servlet名字</servlet-name> <url-pattern>/Servlet名字</url-pattern> </servlet-mapping>
1.自动初始化
当配置中无<load-on-startup></load-on-startup>
时,只有第一次访问此servlet时才会实例化并调用init()方法,当配置了<load-on-startup></load-on-startup>
后,只要开启web服务器就会调用init()方法,设置的整数值越大,表示优先级越大。
相关代码请参考:
Github地址: init初始化代码
Github地址: 发邮件代码
2.读取初始化参数
读取特定名字的参数: this.getServletConfig().getInitParameter("名字")
获取所有参数名字: this.getServletConfig().getInitParameterNames()
相关代码请参考:
Github地址: 读取初始化参数
0 0
- servlet生命周期及web.xml配置
- Servlet的生命周期及web.xml的配置
- web.xml配置以及servlet生命周期
- Servlet接口中的各方法的生命周期及读取web.xml的配置信息
- web.xml配置中的servlet及servlet-mapping
- web.xml配置Servlet
- servlet web.xml配置
- web.xml配置servlet
- web.xml 配置-servlet
- Servlet的生命周期和web.xml
- servlet的web.xml配置
- Web.xml配置Servlet - Excerpts
- servlet 下配置web.xml
- web.xml之Servlet配置
- java web.xml配置servlet
- web.xml中配置servlet
- web.xml中配置servlet
- 转servlet web.xml配置
- js闭包的用处
- Android之Handler用法总结
- python进阶学习笔记(一):打开文件
- 杭电ACm水仙花数2010谁能帮忙分析一下两段代码的区别;第二个通不过啊
- WIN7下的VS2008在调试OpenCV_2.3.1的程序时报错丢失tbb_debug.dll的解决办法~
- servlet生命周期及web.xml配置
- Js Map
- cocos2dx CCTextureCache 、CCSpriteBatchNode 、CCSpriteFrameCache区别
- 蓝桥杯--数字排列
- 28. Implement strStr()
- 条码系统的 存储过程 示例
- PowerDesigner PDM生成OOM问题?
- 杭电ACm求数列的和2009
- 计算机网络——8.IPv6基础