- 浏览: 573831 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
liuzeyuss:
好文章,顶顶
java 线程死锁的检测 -
ysite:
hugh.wang 写道请问你这个能还原吗?短网址用的是HAS ...
Java版短网址(ShortUrl)的算法 -
lv双:
没有注释,看的费劲
java 线程死锁的检测 -
dgj:
好帖子竟然没人顶...
java 线程死锁的检测 -
天空趋虚:
不好,你这只是记录式的博客,不是分享式的博客,对浏览着不友好. ...
一些技术牛人的博客
根据上过一篇日志的内容,测试Servlet生命周期内各个函数的执行顺序。
后台打印结果如下:
测试代码:
我觉得你可以理解为对这个函数的修饰符。
后台打印结果如下:
信息: Server startup in 1078 ms postConstruct! init! get! 2011-1-10 17:16:21 org.apache.coyote.http11.Http11Protocol pause 信息: Pausing Coyote HTTP/1.1 on http-8080 2011-1-10 17:16:22 org.apache.catalina.core.StandardService stop 信息: Stopping service Catalina destory! preDestory! 2011-1-10 17:16:22 org.apache.coyote.http11.Http11Protocol destroy 信息: Stopping Coyote HTTP/1.1 on http-8080
测试代码:
import java.io.IOException; import java.io.PrintWriter; import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class testSequence extends HttpServlet { /** * Destruction of the servlet. <br> */ public void destroy() { //super.destroy(); // Just puts "destroy" string in log // Put your code here System.out.println("destory!"); } /** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is "); out.print(this.getClass()); out.println(", using the GET method"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); System.out.println("get!"); } /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); out .println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">"); out.println("<HTML>"); out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>"); out.println(" <BODY>"); out.print(" This is "); out.print(this.getClass()); out.println(", using the POST method"); out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); System.out.println("post!"); } /** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */ public void init() throws ServletException { // Put your code here System.out.println("init!"); } public @PostConstruct void printAline(){ System.out.println("postConstruct!"); } public @PreDestroy void printSecondLine(){ System.out.println("preDestory!"); } }
评论
2 楼
BabyDuncan
2011-01-15
uule 写道
哥们,这是什么东东?@PostConstruct
我觉得你可以理解为对这个函数的修饰符。
1 楼
uule
2011-01-15
哥们,这是什么东东?@PostConstruct
发表评论
-
一些技术牛人的博客
2011-08-30 13:23 2378High Scalability - Building big ... -
Spring MVC 的请求参数获取的几种方法
2011-07-14 16:11 43860通过@PathVariabl注解获取路径中传递参数 JAVA ... -
Java版短网址(ShortUrl)的算法
2011-07-06 11:59 22445public class Encript { ... -
Spring mvc与JKaptcha组合生成验证码
2011-07-05 16:40 2898kaptcha 是一个非常实用的验证码生成工具。有了它,你可以 ... -
第一次使用resin的安装和配置问题
2011-03-10 17:18 2961那边要求熟悉tomcat和resin,tomcat倒是很熟悉, ... -
jsp页面跳转的方法
2011-03-10 10:02 10961. RequestDispatcher.forward( ... -
实验看看Servlet之间的跳转(dispatch-forward&sendRedirect)
2011-03-07 14:39 1994首先是dispatch-forward 代码如下: R ... -
读取web.xml文件中数据的三种方法
2011-03-04 14:53 4574一,采用web.xml中的init-param标签 web。x ... -
根据responseServlet生成图片验证码
2011-03-04 13:58 1137代码: package com.babyDuncan.re ... -
通过request的请求获取客户端信息
2011-03-04 11:24 2871代码,可以获得很多信息,我只写了几个,其实可以获得更多的! ... -
firstServlet 写一个最基本的servlet程序
2011-03-04 10:53 3112Servlet代码为: package c ... -
Spring的七大模块简介
2011-02-16 11:38 14461Spring有七大功能模块,分别是Spring Core,AO ... -
Servlet获取客户端ip地址和mac地址
2011-01-24 11:35 35944package com.babyDuncan.java; ... -
Servlet相比CGI的好处
2011-01-17 09:20 15081,Servlet是基于Java语言的,拥有java语言的所有 ... -
include指令简介
2011-01-13 11:56 1079incude指令的形式: < ... -
关于foward和redirect的详细描述(比一般的要详细)
2011-01-10 18:03 1650他们是一个Servet跳向另一个Servlet的方法,但是有所 ... -
Servlet生命周期的简单描述
2011-01-10 17:09 2042完整的Servlet的生命周期的描述: 1,服务器加载Serv ... -
Servlet获取上下文参数以及资源注入
2011-01-10 12:07 1827上下文参数可以理解为全局参数,可以支持多个Servlet来调用 ... -
servlet中web.xml的配置
2011-01-10 10:29 1422servlet的web.xml配置: <serv ... -
对Struts的理解
2011-01-07 10:49 1407对 Struts Struts Struts Struts 的 ...
相关推荐
SERVLET生命周期与JSP生命周期比较
servlet生命周期详解
servlet生命周期演示,便于理解servlet工作流程。
Servlet生命周期与工作原理Servlet使用
Servlet生命周期,web开发必须掌握到知识点,其中生命周期也是需要掌握的
servlet生命周期和模版设计模式,包括代码以及相关文档
servlet生命周期详细图解,矢量图。 详细的解释请参考本人博客:http://blog.csdn.net/dwyers/article/details/38435949
关于对Servlet声明周期的图例示意!
达内学习笔记,servlet生命周期,十分详细,保证一看就懂
山寨qq项目1.登录界面教你学会制作qq登录及后台运行。
从三个阶段来描述servlet的生命周期:初始化阶段、运行阶段和销毁阶段。
Java WEB 篇七 Servlet 生命周期
Servlet技术 两条主线 1、HTTP协议 2、Servlet生命周期
Servlet 生命周期
注:本示例中有5章图片,但因为上传比较麻烦,所以就放在附件中 博文链接:https://lvp.iteye.com/blog/234610
Servlet生命周期就是servlet从创建到销毁的过程,包括加载和实例化,初始化,服务,和销毁4步。 当客户第一次请求时,首先判断是否存在servlet对象,第一次请求时不存在,则由tomcat创建对象,调用init()方法对...
JavaEE第1课Servlet入门、生命周期.pptx