关于servlet生命周期中的方法
2013-07-31 13:57
381 查看
关于servlet生命周期中的方法
public class TestServlet extends HttpServlet {
@Override
protected void doGet(
HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
//super.doGet(req, resp);
System.out.println("进入了doGet方法");
resp.setContentType("text/html;charset=gbk");
PrintWriter out = resp.getWriter();
out.write("<h1><font color=red>欢迎进入doGet方法!</font></h1>");
out.flush();
out.close();
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
//super.doPost(req, resp);
System.out.println("进入了doPost方法");
resp.setContentType("text/html;charset=gbk");
PrintWriter out = resp.getWriter();
out.write("<h1><font color=blue>欢迎进入doPost方法!</font></h1>");
out.flush();
out.close();
}
@Override
public void destroy() {
// TODO Auto-generated method stub
//super.destroy();
System.out.println("进入了destory方法");
}
@Override
public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
//super.init(config);
System.out.println("进入了init方法");
String val1 = config.getInitParameter("name1");
String val2 = config.getInitParameter("name2");
System.out.println("初始化的参数值是:name1="+val1+" name2="+val2);
}
}
在页面提交表单后 init方法和doPost方法都会执行,destroy方法需要你在tomcat中关闭时,才执行的方法
public class TestServlet extends HttpServlet {
@Override
protected void doGet(
HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
//super.doGet(req, resp);
System.out.println("进入了doGet方法");
resp.setContentType("text/html;charset=gbk");
PrintWriter out = resp.getWriter();
out.write("<h1><font color=red>欢迎进入doGet方法!</font></h1>");
out.flush();
out.close();
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
//super.doPost(req, resp);
System.out.println("进入了doPost方法");
resp.setContentType("text/html;charset=gbk");
PrintWriter out = resp.getWriter();
out.write("<h1><font color=blue>欢迎进入doPost方法!</font></h1>");
out.flush();
out.close();
}
@Override
public void destroy() {
// TODO Auto-generated method stub
//super.destroy();
System.out.println("进入了destory方法");
}
@Override
public void init(ServletConfig config) throws ServletException {
// TODO Auto-generated method stub
//super.init(config);
System.out.println("进入了init方法");
String val1 = config.getInitParameter("name1");
String val2 = config.getInitParameter("name2");
System.out.println("初始化的参数值是:name1="+val1+" name2="+val2);
}
}
在页面提交表单后 init方法和doPost方法都会执行,destroy方法需要你在tomcat中关闭时,才执行的方法
相关文章推荐
- 二.Servlet生命周期方法
- Servlet生命周期方法,request.getRequestDispatcher
- Servlet生命周期与工作原理
- swif关于ios生命管理周期
- Servlet生命周期与工作原理
- servlet生命周期与工作原理
- Servlet生命周期与工作原理(转)
- Servlet生命周期与工作原理
- Servlet生命周期与工作原理(转载)
- 关于servlet的init方法说明
- Servlet执行过程和Servlet生命周期的区别:
- Unity与Android对比学习之生命周期方法
- 关于Servlet中连接mysql抛出ClassNotFoundException这个异常的解决方法
- Servlet生命周期与原理
- Servlet生命周期与工作原理
- Servlet生命周期与工作原理
- 黑马程序员_Servlet生命周期
- Servlet生命周期与工作原理
- 关于easymock的模拟servlet的doPost的方法的浅例
- Servlet生命周期与工作原理