标签:string 方法 cookie list 分享 context filter 应用 eric
贴上Servlet的常用接口及类,相互关系:
javax.servlet。包含定义Servlet与Servlet容器之间契约的类和接口。
javax.servlet.http。包含HTTP Servlet与Servlet容器直接契约的类和接口。
javax.servlet.annotation。包含对Servlet、Filter、Listener进行标注的注解。
javax.servlet.descriptor。包含为Web应用程序的配置信息提供编程式访问的类型。
(1) servlet接口
所有servlet直接或者间接实现的接口
主要方法:
void init(ServletConfig sc)
ServletConfig getServletConfig()
String getServletInfo();
void service(ServletRequest req,ServletResponse resp)
void destory()
(2) ServletRequest接口和ServletResponse接口
当用户请求到来时,Servlet容器会创建一个ServletRequest对象封装请求数据,同时创建ServletResponse对象封装响应数据
ServletRequest主要方法:
Object getAttribute(String name) //返回属性名为name的属性值
Enumeration getAttributeNames() //返回请求中所有的属性
void removeAttribute(String name)
void setAttribute(String name,Object obj)
String getCharacterEncoding();
String getParameter(String name)//返回请求name参数的值
Enumeration getParameterNames()
ServletOutputStream getOutputStream() //用来发送对客户端的响应
PrintWrite getWrite() //用来将字符文本发送到客户端 out.println("daduh");
待续。。。下同。。。
它重写了service方法,针对客户请求类型不同提供不同的方法:doPost(),doGet()
Cookie[] getCookies();
HttpSession getSession();
void addCookie(Cookie cookie);
String getId()
String getAttribute(String name)
void setAttribute(String name,Object obj)
Enumeration getAttributeNames()
标签:string 方法 cookie list 分享 context filter 应用 eric
原文地址:https://www.cnblogs.com/chenloveslife/p/8922118.html