設置page范圍的JavaBean
01
<%@page language="java" contentType="text/html;charset=gb2312"%>
02
<!DOCTYPE html>
03
<html>
04
<head>
05
<title>設置page的范圍</title>
06
</head>
07
<body>
08
<%--通過useBean動作指令調用JavaBean--%>
09
<jsp:useBean id="user" scope="<span style="color:#e53333;">page</span>" class="com.javaweb.ch07.UserBean"></jsp:useBean>
10
<%--根據所有的參數設置JavaBean中屬性--%>
11
<jsp:setProperty name="user" property="username" value="page_username"/>
12
<jsp:setProperty name="user" property="password" value="page_password"/>
13
<jsp:forward page="PageJavaBeanDemo2.jsp"/>
14
</body>
15
</html>
01
<%@page language="java" contentType="text/html;charset=gb2312"%>
02
<!DOCTYPE html>
03
<html>
04
<head>
05
<title>設置page的范圍</title>
06
</head>
07
<body>
08
<%--通過useBean動作指令調用JavaBean--%>
09
<jsp:useBean id="user" scope="<span style="color:#e53333;">page</span>" class="com.javaweb.ch07.UserBean"></jsp:useBean>
10
<%--根據所有的參數設置JavaBean中屬性--%>
11
<jsp:getProperty name="user" property="username" />
12
<jsp:getProperty name="user" property="password" />
13
</body>
14
</html>
設置request范圍的JavaBean
01
<%@page language="java" contentType="text/html;charset=gb2312"%>
02
<!DOCTYPE html>
03
<html>
04
<head>
05
<title>設置page的范圍</title>
06
</head>
07
<body>
08
<%--通過useBean動作指令調用JavaBean--%>
09
<jsp:useBean id="user" scope="<b><span style="color:#e53333;">request</span></b>" class="com.javaweb.ch07.UserBean"></jsp:useBean>
10
<%--根據所有的參數設置JavaBean中屬性--%>
11
<jsp:setProperty name="user" property="username" value="request_username"/>
12
<jsp:setProperty name="user" property="password" value="request_password"/>
13
<jsp:forward page="PageJavaBeanDemo2.jsp"/>
14
</body>
15
</html>
01
<%@page language="java" contentType="text/html;charset=gb2312"%>
02
<!DOCTYPE html>
03
<html>
04
<head>
05
<title>設置page的范圍</title>
06
</head>
07
<body>
08
<%--通過useBean動作指令調用JavaBean--%>
09
<jsp:useBean id="user" scope="<span style="color:#e53333;">request</span>" class="com.javaweb.ch07.UserBean"></jsp:useBean>
10
<%--根據所有的參數設置JavaBean中屬性--%>
11
<jsp:getProperty name="user" property="username" />
12
<jsp:getProperty name="user" property="password" />
13
</body>
14
</html>
設置session范圍的JavaBean
01
<%@page language="java" contentType="text/html;charset=gb2312"%>
02
<!DOCTYPE html>
03
<html>
04
<head>
05
<title>設置page的范圍</title>
06
</head>
07
<body>
08
<%--通過useBean動作指令調用JavaBean--%>
09
<jsp:useBean id="user" scope="session" class="com.javaweb.ch07.UserBean"></jsp:useBean>
10
<%--根據所有的參數設置JavaBean中屬性--%>
11
<jsp:setProperty name="user" property="username" value="session_username"/>
12
<jsp:setProperty name="user" property="password" value="session_password"/>
13
<a href="PageJavaBeanDemo2.jsp">跳轉到PageJavaBeanDemo2.jsp</a>
14
</body>
15
</html>
01
<%@page language="java" contentType="text/html;charset=gb2312"%>
02
<!DOCTYPE html>
03
<html>
04
<head>
05
<title>設置page的范圍</title>
06
</head>
07
<body>
08
<%--通過useBean動作指令調用JavaBean--%>
09
<jsp:useBean id="user" scope="session" class="com.javaweb.ch07.UserBean"></jsp:useBean>
10
<%--根據所有的參數設置JavaBean中屬性--%>
11
<jsp:getProperty name="user" property="username" />
12
<jsp:getProperty name="user" property="password" />
13
</body>
14
</html>
設置application范圍的JavaBean
01
<%@page language="java" contentType="text/html;charset=gb2312"%>
02
<!DOCTYPE html>
03
<html>
04
<head>
05
<title>設置page的范圍</title>
06
</head>
07
<body>
08
<%--通過useBean動作指令調用JavaBean--%>
09
<jsp:useBean id="user" scope="application" class="com.javaweb.ch07.UserBean"></jsp:useBean>
10
<%--根據所有的參數設置JavaBean中屬性--%>
11
<jsp:setProperty name="user" property="username" value="application_username"/>
12
<jsp:setProperty name="user" property="password" value="application_password"/>
13
<a href="PageJavaBeanDemo2.jsp">跳轉到PageJavaBeanDemo2.jsp</a>
14
</body>
15
</html>
01
<%@page language="java" contentType="text/html;charset=gb2312"%>
02
<!DOCTYPE html>
03
<html>
04
<head>
05
<title>設置page的范圍</title>
06
</head>
07
<body>
08
<%--通過useBean動作指令調用JavaBean--%>
09
<jsp:useBean id="user" scope="application" class="com.javaweb.ch07.UserBean"></jsp:useBean>
10
<%--根據所有的參數設置JavaBean中屬性--%>
11
<jsp:getProperty name="user" property="username" />
12
<jsp:getProperty name="user" property="password" />
13
</body>
14
</html>
摘自 張大鵬的博客