jsp---设置JavaBean的范围

来源:岁月联盟 编辑:exp 时间:2012-02-06
设置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>


摘自 张大鹏的博客