jsp内置对象之-pageContext对象

付费节点推荐


免费节点


节点使用教程


pageContext对象:

常用方法如下:

  • JspWriter getOut() 返回当前客户端响应被使用的JspWriter流(out).
  • HttpSession getSession() 返回当前页中的HttpSession对象(session)。
  • Object getPage() 返回当前页的Object对象(page).
  • ServletRequest getRequest() 返回当前页的ServletRequest对象(request).
  • ServletResponse getResponse() 返回当前页的ServletResponse对象(response)。
  • void setAttribute(String name,Object attribute) 设置属性及属性值。
  • Object getAttribute(String name,int scope) 在指定范围内取属性的值。
  • int getAttributeScope(String name) 返回某实行的作用范围。
  • void forward(String relativeUrlPath) 使当前页面重导到另一页面。
  • void include(String relativeUrlPath) 在当前位置包含另一文件。

[t]PageContext.jsp[/t]

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>pageContext内置对象</title>
</head>
<body>
<h1>pageContext内置对象</h1>
用户名:<%=pageContext.getSession().getAttribute("username") %><br />
<%
pageContext.forward("reg.jsp");
%>
<%
pageContext.include("page_include.jsp");
%>
</body>
</html>

[t]page_include.jsp[/t]
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>pageContext内置对象-include方法</title>
</head>
<body>
<h1>pageContext内置对象-include方法</h1><hr />
<%
Date date=new Date();
SimpleDateFormat time=new SimpleDateFormat("YYYY年MM月dd日HH时MM分ss秒.");
String s=time.format(date);
out.println(s+"&nbsp;&nbsp;");
%>
</body>
</html>

未经允许不得转载:Bcoder资源网 » jsp内置对象之-pageContext对象

相关推荐

更多优质资源关注微信公众号: bcoder

bcoder
赞 (0)
分享到:更多 ()

评论 0

评论前必须登录!

登陆 注册