HttpServlet在第一个Servlet程序中的知识点

##HttpServlet是GenericServlet 的子类

HttpServlet是GennericServlet的子类,只用于接收Http请求和响应。
一般情况,web开发中,需要使用的Servlet均只需要实现该类即可,
servlet.http包中定义了采用HTTP通信协议的HttpServlet类,
HTTP的请求方式包括DELETE,GET,OPTIONS,POST,PUT和TRACE,
在HttpServlet类中分别提供了相应的服务方法,它们是,
doDelete(),doGet(),doOptions(),doPost(), doPut()和doTrace().

HttpServlet容器响应Web客户请求流程如下:

1)Web客户向Servlet容器发出Http请求;

2)Servlet容器解析Web客户的Http请求;

3)Servlet容器创建一个HttpRequest对象,在这个对象中封装Http请求信息;

4)Servlet容器创建一个HttpResponse对象;

5)Servlet容器调用HttpServlet的service方法,
把HttpRequest和HttpResponse对象作为service方法的参数传给HttpServlet对象;

6)HttpServlet调用HttpRequest的有关方法,获取HTTP请求信息;

7)HttpServlet调用HttpResponse的有关方法,生成响应数据;

8)Servlet容器把HttpServlet的响应结果传给Web客户。

在myeclipse和idea中创建的Servlet都默认继承了Service(),但是没有显示出来,

只需要重写其中的get,post就是Servlet里的doGet(),doPost()

制作一个表单

在HTML中

<form method="get  post" action="index.jsp(一般是servlet)">

有methed=get和methed=post两种

设置get会在访问地址里显示信息,相当于以信息的形式传送数据库

设置post会隐藏信息,以地址的形式显示,但是数据也可以传送。

猜你喜欢

转载自www.cnblogs.com/blogwwx/p/12587357.html