详解jsp开发中的内置对象

来源:互联网  作者:本站整理
摘要:1.request对象客户端的请求信息被封装在request对象中,通过它才能了解到客户的需求,然后做出响应。它是HttpServletRequest类的实例。序号/方 法/说 明1 object getAttribute(String n……

8.pageContext对象

pageContext对象提供了对JSP页面内所有的对象及名字空间的访问,也就是说他可以访问到本页所在的SESSION,也可以取本页面所在的application的某一属性值,他相当于页面中所有功能的集大成者,它的本 类名也叫pageContext。

序号/方 法/说 明
1   JspWriter getOut() 返回当前客户端响应被使用的JspWriter流(out)
2   HttpSession getSession() 返回当前页中的HttpSession对象(session)
3   Object getPage() 返回当前页的Object对象(page)
4   ServletRequest getRequest() 返回当前页的ServletRequest对象(request)
5   ServletResponse getResponse() 返回当前页的ServletResponse对象(response)
6   Exception getException() 返回当前页的Exception对象(exception)
7   ServletConfig getServletConfig() 返回当前页的ServletConfig对象(config)
8   ServletContext getServletContext() 返回当前页的ServletContext对象(application)
9   void setAttribute(String name,Object attribute) 设置属性及属性值
10   void setAttribute(String name,Object obj,int scope) 在指定范围内设置属性及属性值
11   public Object getAttribute(String name) 取属性的值
12   Object getAttribute(String name,int scope) 在指定范围内取属性的值
13   public Object findAttribute(String name) 寻找一属性,返回起属性值或NULL
14   void removeAttribute(String name) 删除某属性
15   void removeAttribute(String name,int scope) 在指定范围删除某属性
16   int getAttributeScope(String name) 返回某属性的作用范围
17   Enumeration getAttributeNamesInScope(int scope) 返回指定范围内可用的属性名枚举
18   void release() 释放pageContext所占用的资源
19   void forward(String relativeUrlPath) 使当前页面重导到另一页面
20   void include(String relativeUrlPath) 在当前位置包含另一文件

<%@page contentType="text/html;charset=gb2312"%>
<html><head><title>pageContext对象_例1</title></head>
<body><br>
<%
request.setAttribute("name","霖苑编程");
session.setAttribute("name","霖苑计算机编程技术培训");
//session.putValue("name","计算机编程");
application.setAttribute("name","培训");
%>
request设定的值:<%=pageContext.getRequest().getAttribute("name")%><br>
session设定的值:<%=pageContext.getSession().getAttribute("name")%><br>
application设定的值:<%=pageContext.getServletContext().getAttribute("name")%><br>
范围1内的值:<%=pageContext.getAttribute("name",1)%><br>
范围2内的值:<%=pageContext.getAttribute("name",2)%><br>
范围3内的值:<%=pageContext.getAttribute("name",3)%><br>
范围4内的值:<%=pageContext.getAttribute("name",4)%><br>
<!--从最小的范围page开始,然后是reques、session以及application-->
<%pageContext.removeAttribute("name",3);%>
pageContext修改后的session设定的值:<%=session.getValue("name")%><br>
<%pageContext.setAttribute("name","应用技术培训",4);%>
pageContext修改后的application设定的值:<%=pageContext.getServletContext().getAttribute("name")%><br>
值的查找:<%=pageContext.findAttribute("name")%><br>
属性name的范围:<%=pageContext.getAttributesScope("name")%><br>
</body></html>

9.config对象

config对象是在一个Servlet初始化时,JSP引擎向它传递信息用的,此信息包括Servlet初始化时所要用到的参数(通过属性名和属性值构成)以及服务器的有关信息(通过传递一个ServletContext对象)

序号/方 法/说 明
1   ServletContext getServletContext() 返回含有服务器相关信息的ServletContext对象
2   String getInitParameter(String name) 返回初始化参数的值
3   Enumeration getInitParameterNames() 返回Servlet初始化所需所有参数的枚举

【相关文章】好搜一下
详解CCProxy代理服务器软件的帐号管理和使用方法

详解CCProxy代理服务器软件的帐号管理和

1、帐号管理基本概念 代理服务器CCProxy的帐号管理分为三个部分。分别是允许…