pageContext对象

来源:互联网 发布:手机端淘宝店招怎么做 编辑:程序博客网 时间:2024/05/29 17:00

pageContext对象可操作request、response、session、out等对象中的数据,需要使用它们的相应对象进行操作

pageContext对象提供了对JSP页面所有的对象及命名空间的访问

getRequest() 用于返回当前的request对象

getResponse() 用于返回当前的response对象

getSession() 用于返回当前的session对象

getOut() 用于反悔当前页面的out对象

getException() 用于返回当前的exception对象

getServletContext() 用于返回当前页面的application对象

findAttribute(String name) 用于按照页面、请求、会话以及应用程序范围的顺序实现对某个已命名属性的搜索,返回其属性值或null

forward(String relativeUrlPath) 用于把页面重新定向到另一个页面或者Servlet组件上

moveAttribute(String name) 用于删除默认页面范围或特定对象范围之中的已命名对象

release() 用于释放pageContext所占资源

include(String relativeUrlPath) 用于在当前位置包含另一文件

setAttribute(String name, Object attribute) 用于设置指定属性及属性值

setAttribute(String name, Object obj, int scope) 用于在指定范围内设置指定属性及值

getAttribute(String name, int scope) 用于在指定范围内获取指定属性的值

getAttribute(String name) 用于获取指定属性的值

实例:

    request.setAttribute("name", "yhc");    session.setAttribute("name", "yhc");    application.setAttribute("name", "yhc");    request对象中的值<%=pageContext.getRequest().getAttribute("name")%>    session    application <%=pageContext.getServletContext().getAttribute("name")%>
0 0
原创粉丝点击