Servlet常用接口及类之间的关系

贴上Servlet的常用接口及类,相互关系:

1.servlet接口
所有servlet直接或者间接实现的接口
主要方法:
void init(ServletConfig sc)
ServletConfig getServletConfig()
String getServletInfo();
void service(ServletRequest req,ServletResponse resp)
void destory()
2.HtppServlet抽象类
它重写了service方法,针对客户请求类型不同提供不同的方法:doPost(),doGet()
3.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");
4.HttpServletRequest接口
Cookie[] getCookies();
HttpSession getSession();
5.HttpServletResponse接口
void addCookie(Cookie cookie);
6.HttpSession接口
String getId()
String getAttribute(String name)
void setAttribute(String name,Object obj)
Enumeration getAttributeNames()

猜你喜欢

转载自www.cnblogs.com/chenloveslife/p/8922118.html
今日推荐