pageContext对象
来源:互联网 发布:2017网络综艺节目排名 编辑:程序博客网 时间:2024/06/13 23:29
pageContext对象是很强大的,可以用pageContext对象可以取得request,response等的对象,他是javax.servlet.jsp.pageContext类的实例,主要表示jsp的上下文
常用方法
1. public abstract void forward(String relativeUrlPath) throws ServletException,IOException
2. public void include(String relativeUrlPath) throws ServletException,IOException
3. public ServletConfig getServletConfig()
4. public ServletContext getServletContext()
5. public ServletRequest getRequest()
6. public ServletResponse getResponse()
7. public HttpSession getSession()
pageContext主要功能是在JSP文件的支持,功能强大,可以操作各种内置对象
我们来实现一个地址跳转的功能,首先是第一个页面:
<%@ page contentType="text/html" pageEncoding="utf-8" language="java" %><%@ page import="java.util.*"%><!DOCTYPE html><html><head><title></title></head><body><%pageContext.forward("pageContext_demo_02.jsp?name=liuke");%></body></html>
第二个页面来取得数据,注意此时用pageContext来取request对象
<%@ page contentType="text/html" pageEncoding="utf-8" language="java" %><%@ page import="java.util.*"%><!DOCTYPE html><html><head><title></title></head><body><%String name = pageContext.getRequest().getParameter("name");String path = pageContext.getServletContext().getRealPath("/");%>姓名:<%= name%><br>虚拟目录完整路径:<%= path%></body></html>
总结:注意一点,在返回request、response对象的时候返回的是ServletRequest和ServletResponse所以有些需要HttpServletRequest和HttpServletResponse来操作的东西现在是不能用的,这点很重要
阅读全文
0 0
- pageContext对象
- pageContext对象
- pageContext对象
- pageContext对象
- pageContext对象
- pageContext对象
- PageContext对象
- pageContext对象
- pageContext对象
- pageContext对象
- pageContext对象
- pageContext对象
- pageContext对象
- pageContext对象
- pageContext对象
- pageContext对象
- pageContext对象
- pageContext对象
- PAT考试乙级1056(C语言实现)
- 深入学习ThreadLocal和InheritableThreadLocal
- Vue2+VueRouter2+Webpack+Axios 构建项目实战2017重制版(十)打包项目并发布到子目录
- 有序链表的插入
- 聚集索引和非聚集索引(整理)
- pageContext对象
- 江城子篇-一道很模板的Splay题-洛谷P3369
- Android 线程学习
- SDIO 接口 Wifi 驱动流程分析 (AP6354)
- Android中View.setId()
- Inductive Representation Learning On Large Graphs【阅读笔记】
- 编译最新版webrtc源码
- C#并行运行迭代(循环),提高运行效率
- 重定向和转发技术的使用场景