b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

aspnet responsewrite乱码_responsebody返回json_框架设response乱码(5)

电脑杂谈  发布时间:2017-03-10 09:15:41  来源:网络整理

8. logs Tomcat日志文件夹

9. lib 执行依赖的JAR

Servlet的生命周期

1.servlet的生命周期分为初始化阶段,运行阶段,销毁阶段

2.初始化阶段,销毁阶段在整个servlet的生命周期中只执行一次,运行阶段可执行多次。

3.初始化阶段执行init方法,运行阶段执行service方法,销毁阶段执行destory方法。

4.生命周期

1)初始化阶段:web容器调用init方法,执行初始化操作,执行一些参数的初始化操作

2) 运行阶段:web容器调用service方法,将当前请求的信息封装成ServletRequest对象,并且将要响应的信息对象ServletResponse对象创建并将这两个对象作为参数传递给service方法;

在service方法中处理请求,并将响应结果封装在ServletResponse对象中,由web容器返回给浏览器

3 销毁阶段:当前容器关闭的时候执行,一般会将资源关闭回收的操作在其中执行。

4.servlet代码示例

5.servlet和JSP的关系

1)JSP在本质上就是servlet,web服务器总是把被访问的各个JSP文件先翻译成对应的servlet,然后在编译执行。

2)以tomcat服务器为例,JSP对应的servlet存放在Tomcat主目录的\work\catalina\locahost目录下

3)jsp最终以servlet的形式为客户端提供服务。

6.在servlet的生命周期中常被调用的方法

1)void init(ServletConfig config) throws ServletException

Called by the servlet container to indicate to a servlet that the servlet is being placed into service.

The servlet container calls the init method exactly once after instantiating the servlet. The init method must complete successfully before the servlet can receive any requests.

2)void service(ServletRequest req, ServletResponse res) throws ServletException, java.io.IOException

Called by the servlet container to allow the servlet to respond to a request.

This method is only called after the servlet's init() method has completed successfully.每当用户请求servlet时,都会被调用,用来处理用户请求并返回响应结果。

3)void destroy()

Called by the servlet container to indicate to a servlet that the servlet is being taken out of service. This method is only called once all threads within the servlet's service method have exited or after a timeout period has passed. After the servlet container calls this method, it will not call the service method again on this servlet当servlet被卸载时,destroy方法被执行以回收servlet启用的资源


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-36808-5.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    • 刘倩倩
      刘倩倩

      首先是判明其意图和性质

    热点图片
    拼命载入中...