JSP学习笔记(8)_Servlet
来源:互联网 发布:淘宝店铺各种图片尺寸 编辑:程序博客网 时间:2024/06/18 10:58
JSP学习笔记(8)_Servlet(1)
1.结构体系
HttpServlet <---(子类)--- GenericServlet(抽象类) ---(实现)---> (1)(2)(3)
(1)Servlet (interfance)
(2)ServletConfig (interfance)
(3)Serializable (interfance) 序列化接口
2.特点
跨平台,可移植性
3.效率
比JSP效率高
4.简单实现
public class Test01 implements Servlet{public void destroy() {// TODO Auto-generated method stubSystem.out.println("killed!!!");}public ServletConfig getServletConfig() {// TODO Auto-generated method stubreturn null;}public String getServletInfo() {// TODO Auto-generated method stubreturn null;}public void init(ServletConfig config) throws ServletException {// TODO Auto-generated method stubSystem.out.println("出现了!!");}public void service(ServletRequest req, ServletResponse res)throws ServletException, IOException {// TODO Auto-generated method stub//System.out.println("服务中...");HttpServletRequest request = (HttpServletRequest)req;HttpServletResponse response = (HttpServletResponse)res;String username = request.getParameter("username");PrintWriter out = response.getWriter();out.println("<html><head></head><body>");out.println("<h1>hello "+username+"!</h1>");out.println("</body></html>");}}方法以及作用:public void destroy()// 当服务器内存不足而导致servlet对象被调度或者关闭服务器时,serlet对象销毁前执行
public ServletConfig getServletConfig()// 用于获取config对象public String getServletInfo()// 用于获取servlet的说明信息public void init(ServletConfig config) throws ServletException// 用于执行对象创建后{构造器执行后}的初始化操作,在整个Servlet对象的生命周期中运行且只运行一次public void service(ServletRequest req, ServletResponse res)throws ServletException, IOException// 用于对外提供服务,响应客户请求[URL],该方法以多线程的方式对外提供服务,服务完毕则常驻内存
阅读全文
0 0
- JSP学习笔记(8)_Servlet
- Servlet学习笔记_Servlet
- 张志宇 SERVELET JSP学习讲义-07_SERVLET为什么有2个init方法
- 张志宇 SERVELET JSP学习讲义-08_SERVLET如何从上一个页面取得参数
- Java精选笔记_Servlet技术
- JSP学习笔记(一):JSP基础
- JSP学习笔记(一):JSP标签
- JSP学习笔记(1)-JSP简介
- JSP学习笔记(2)-JSP语法
- 宋利兴_笔记_Servlet的应用
- Java精选笔记_Servlet事件监听器
- jsp---学习笔记(一)
- JSP学习笔记(1)
- JSP学习笔记(1)
- JSP学习笔记(一)
- JSP学习笔记(二)
- JSP学习笔记(一)
- JSP学习笔记(1)
- 代码规范(不定时更新)
- 十字架
- Ajax的Url
- elementui 限制选择范围 disabledData
- Hibernate的class_name.hbm.xml中component的使用
- JSP学习笔记(8)_Servlet
- Service进程防杀
- form表单提交onclick和onsubmit
- 解决oracle存储过程死锁问题
- shell常用命令
- 邮件发送代码片段
- protocol .proto文件转.java文件
- Unity_NGUI基础控件_ScrollView_042
- Hive集合数据类型