当前位置:编程学习 > JAVA >>

jsp---设置JavaBean的范围

设置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;char
补充:Web开发 , Jsp ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,