Servlet
3.2 Servlet特性和生命周期
3.2.1 Servlet线程特征
Servlet是运行在服务器端的组件,能够个客户端返回动态页面
web应用服务器将为每个客户端的连接启动一个线程来服务
3.2.2 Servlet生命周期
Servlet生命周期是servlet对象从创建到调用,到最后的销毁的整个过程。
1.加载和实例化; 3.服务
2.初始化; 4.销毁
3.3 Servlet请求类型
GET:向服务器发送检索数据请求
POST:发送数据,创建新的表格
PUT:发送需要更新的数据
DELETE:发送删除资源的请求
Servlet默认可用的请求是get和post,对应的是doGet方法和doPost方法。继承HttpServlet后,重写调用方法即可。
3.3.1 get请求
doget方法接收get请求,用于数据的查询。通常使用超链接发起请求。

/*`@OVERRIDE` `Protected void doGet(HttpServletRequest req,HttpServletResponse resp) throws servletException,IOException{` `resp.setCharacterEncoding("utf-8"); resp.setContentTypeAA("text/html;charset=utf-8"); Printwriter out =resp.getwriter(); out.writer("这是调用了dopost方法得到的页面内容"); out.writer("
您好,世界!
") out.flush(); out.close();}`*/
3.3.2 Post请求
doPost请求接收post请求,用于数据的增加、更新和删除操作。

浙公网安备 33010602011771号