分类:
第一类:与Servlet有关:page和config
第二类:与Input/Output有关:out,request和response
第三类:与Context有关:application,session和pageContext
第四类:与Error有关:exception
1:request:该对象作用范围仅仅在一次请求之间,即当在浏览器发起请求到服务器响应之间。注意:当在服务器配置了转发时,该request对象是会被传递的,这也就是两个请求之间参数可以共用的原因,因为他们共用了同一个request对象。
2:response:即在客户访问服务器之后,服务器响应客户端的对象,服务器会通过response对象将响应信息返回给客户端。其中包含消心头信息。主要方法介绍如下:
public abstract class PageContext extends JspContext {
public PageContext() {
}
public abstract void initialize(Servlet servlet,
ServletRequest servletrequest, ServletResponse servletresponse,
String s, boolean flag, int i, boolean flag1) throws IOException,
IllegalStateException, IllegalArgumentException;
public abstract void release();
public abstract HttpSession getSession();
public abstract Object getPage();
public abstract ServletRequest getRequest();
public abstract ServletResponse getResponse();
public abstract Exception getException();
public abstract ServletConfig getServletConfig();
public abstract ServletContext getServletContext();
public abstract void forward(String s) throws ServletException, IOException;
public abstract void include(String s) throws ServletException, IOException;
public abstract void include(String s, boolean flag)
throws ServletException, IOException;
public abstract void handlePageException(Exception exception)
throws ServletException, IOException;
public abstract void handlePageException(Throwable throwable)
throws ServletException, IOException;
public BodyContent pushBody() {
return null;
}
public ErrorData getErrorData() {
return new ErrorData((Throwable) getRequest().getAttribute(
"javax.servlet.error.exception"), ((Integer) getRequest()
.getAttribute("javax.servlet.error.status_code")).intValue(),
(String) getRequest().getAttribute(
"javax.servlet.error.request_uri"),
(String) getRequest().getAttribute(
"javax.servlet.error.servlet_name"));
}
public static final int PAGE_SCOPE = 1;
public static final int REQUEST_SCOPE = 2;
public static final int SESSION_SCOPE = 3;
public static final int APPLICATION_SCOPE = 4;
public static final String PAGE = "javax.servlet.jsp.jspPage";
public static final String PAGECONTEXT = "javax.servlet.jsp.jspPageContext";
public static final String REQUEST = "javax.servlet.jsp.jspRequest";
public static final String RESPONSE = "javax.servlet.jsp.jspResponse";
public static final String CONFIG = "javax.servlet.jsp.jspConfig";
public static final String SESSION = "javax.servlet.jsp.jspSession";
public static final String OUT = "javax.servlet.jsp.jspOut";
public static final String APPLICATION = "javax.servlet.jsp.jspApplication";
public static final String EXCEPTION = "javax.servlet.jsp.jspException";
}
4:session:这个对象使用率较高,使用难度也较大,待会儿会有单独的讲解文章,需要了解请关注博客更新。
5:application:应用上下文对象,是存活范围最大的对象,只要服务器没有关闭,application对象中的数据就会一直存在。在整个服务器运行过程当中,application对象只有一个。因此它会被所有的用户共享。
6:out输出对象,用来输出页面信息,主要方法:
7:config对象提供一些配置信息,常用的方法有getInitParameter和getParameterNames,以获得Servlet初始化时得参数。
8:page对象代表了正在运行的jsp文件产生的类对象,不建议一般读者使用。具体看下jsp生成的类的源码就知道了。
9:exception对象代表了jsp文件运行时所产生的异常对象,此对象不能再一般jsp文件中直接使用,而只能在使用了“<%@ isErrorPage=”true“%>”的jsp文件中使用.
例如:<%@ page language="java" import="java.util.*" pageEncoding="utf-8" isErrorPage="false"%>
这个一般会和errorPage=""搭配使用,errorPage是指页面出现异常时跳转到哪个出错提示页面,即上面配置的页面。
此图来自张龙讲师的教程。具体讲解有时间再补上。刚毕业的同学面试时经常会被问到。