程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> jsp---設置JavaBean的范圍

jsp---設置JavaBean的范圍

編輯:關於JSP

設置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>


摘自 張大鵬的博客

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved