jsp代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP '11.jsp' starting page</title>
</head>
<body>
<!-- pageContext对象用在自定义标签开发技术里面
jsp页面最好不要出现java代码,可是很难避免使用<% %>,
里面都是java代码,所以就需要用java类开发自定义标签(<fix:viewData/>),
而传过去八大对象很麻烦,所以用pageContext封装了八大对象
直接传递pageContext对象即可-->
<%
String data = (String)request.getAttribute("data");
out.write(data);
//pageContext也是page域对象,他的范围是当前页面,jsp结束则其消失
pageContext.setAttribute("data","aaaa");
%>
<fix:viewData/>--------java
</body>
</html>
jsp代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>pageContext对象访问其他域</title>
</head>
<body>
<%
request.setAttribute("data","aaa");
//从其他域中获取数据
String data = (String)pageContext.getAttribute("data",PageContext.REQUEST_SCOPE);
out.write(data);
//findAttribute从其他域中自动寻找数据,很方便
//按域从小到大的顺序找数据 page request session application
//效果等同于 el表达式里的${data}
pageContext.findAttribute("data");
%>
</body>
</html>
jsp代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>pageContext对象的其他常用方法</title>
</head>
<body>
<%
pageContext.forward("/1.jsp");
pageContext.include("foot.jsp");
%>
</body>
</html>