servlet中一共包括两个包:javax.servlet和javax.servlet.http
首先来看javax.servlet
1:接口:
1.1 首先介绍两个最常用也是最重要的接口,servletRequest和servletResponse.这两个是孪生 兄弟,按照官方的话说,servletRequest就是把客户端的信息封装起来传递给服务器,而后服务器会把这个对象作为一个参数传递给特定的 servlet的service方法 (Defines an object to provide client request information to a servlet. The servlet container creates a ServletRequest object and passes it as an argument to the servlet's service method. , 而servletResponse则是相反,把准备好的东东打包成一个servletResponse对象,并生成静态页面(html)传递给客户端,以 供显示 (Defines an object to assist a servlet in sending a response to the client. The servlet container creates a ServletResponse object and passes it as an argument to the servlet's service method).
1.2 接着是servletContext,也就是传说中的上下文(好难理解的三个字),官方定义是一个能与 servlet容器打交道的对象,每个web应用都会有一个 (There is one context per "web application" per Java Virtual Machine),相当 于说它那里存放着整个web应用的全局变量.,另外,它是包括在接口servletConfig中的.
1.3 servletConfig,看名字就知道是servlet容器配置的对象啦 (A servlet configuration object used by a servlet container to pass information to a servlet during initialization)
首先来看javax.servlet
1:接口:
1.1 首先介绍两个最常用也是最重要的接口,servletRequest和servletResponse.这两个是孪生 兄弟,按照官方的话说,servletRequest就是把客户端的信息封装起来传递给服务器,而后服务器会把这个对象作为一个参数传递给特定的 servlet的service方法 (Defines an object to provide client request information to a servlet. The servlet container creates a ServletRequest object and passes it as an argument to the servlet's service method. , 而servletResponse则是相反,把准备好的东东打包成一个servletResponse对象,并生成静态页面(html)传递给客户端,以 供显示 (Defines an object to assist a servlet in sending a response to the client. The servlet container creates a ServletResponse object and passes it as an argument to the servlet's service method).
1.2 接着是servletContext,也就是传说中的上下文(好难理解的三个字),官方定义是一个能与 servlet容器打交道的对象,每个web应用都会有一个 (There is one context per "web application" per Java Virtual Machine),相当 于说它那里存放着整个web应用的全局变量.,另外,它是包括在接口servletConfig中的.
1.3 servletConfig,看名字就知道是servlet容器配置的对象啦 (A servlet configuration object used by a servlet container to pass information to a servlet during initialization)