Servlet接口中的方法及说明

来源:互联网 发布:python 股票数据库 编辑:程序博客网 时间:2024/05/21 06:12

1、Servlet接口中的方法及说明
public void init(ServletConfig config);
public void service(ServletRequest request,ServletResponse response); //处理客户端请求
public void destroy();
public ServletConfig getServletConfig();
public String getServletInfo();

2、SerlvetConfig接口
public String getInitParameter(String name);
public Enumeration getInitParameterNames();//获得所有初始化参数名的集合
public ServletContext getServletContext();//获取Servlet上下文对象
public String getServletName();//返回Servlet对象的实例名

3、HttpServletRequest接口
public String getContextPath();//返回请求的上下文路径
public Cookie[] getCookies();//返回请求中发送的所有cookie对象,返回值为cookie数组
public String getMethod();//返回请求类型
public String getQueryString();//返回请求中参数的字符串形式,如请求MyServlet?username=mr,则返回username=mr
public String getRequestURI();//返回主机名到请求参数之间的字符串形式
public StringBuffer getRequestURL();//返回请求URL,不包含请求参数。
public String getServletPath();//返回请求URI中的Servlet路径字符串,不包含请求参数
public HttpSession getSession();

4、HttpServletResponse接口
public void addCookie();//向客户端写入cookie
public void sendError(int sc);//发送一个错误状态码为sc的错误响应到客户端
public void sendError(int sc,String msg);//发送包含错误状态码及错误信息的响应到客户端,sc为错误码,msg为错误信息
public void sendRedirect(String location);//使客户端重定向到新的URL

原创粉丝点击