最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JavaBean四個(gè)作用域范圍的詳解

 更新時(shí)間:2017年10月12日 10:09:39   作者:cakin24  
這篇文章主要介紹了JavaBean四個(gè)作用域范圍的詳解的相關(guān)資料,希望通過(guò)本文能幫助到大家,需要的朋友可以參考下

JavaBean四個(gè)作用域范圍的詳解

一 說(shuō)明

使用useBeans的scope屬性可以用來(lái)指定javabean的作用范圍。

 二 四個(gè)作用范圍


 

三 代碼

1、login.jsp

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
  
  <title>My JSP 'login.jsp' starting page</title>
  
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">  
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
    -->
 
 </head>
 
 <body>
  <h1>系統(tǒng)登錄</h1>
  <hr>
  <form name="loginForm" action="dologin.jsp?mypass=999999" method="post">
   <table>
    <tr>
     <td>用戶名:</td>
     <td><input type="text" name="username" value=""/></td>
    </tr>
    <tr>
     <td>密碼:</td>
     <td><input type="password" name="password" value=""/></td>
    </tr>
    <tr>
     <td colspan="2" align="center"><input type="submit" value="登錄"/></td>
     
    </tr>
   </table>
  </form>
 </body>
</html>

2、dologin.jsp

<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
  
  <title>My JSP 'dologin.jsp' starting page</title>
  
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">  
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
    -->
 
 </head>
 
 <body>
  <jsp:useBean id="myUsers" class="com.po.Users" scope="page"/>
  <h1>setProperty動(dòng)作元素</h1>
  <hr>
  <!--根據(jù)表單自動(dòng)匹配所有的屬性 -->
  <%--
  <jsp:setProperty name="myUsers" property="*"/> 
  --%>
  <!--根據(jù)表單匹配所有部分的屬性 -->
  <%--
  <jsp:setProperty name="myUsers" property="username"/> 
  --%>
  <!--根表單無(wú)關(guān),通過(guò)手工賦值給屬性 -->
  <%--
  <jsp:setProperty name="myUsers" property="username" value="lisi"/>
  <jsp:setProperty name="myUsers" property="password" value="888888"/>
  --%>
  <!--通過(guò)URL傳參數(shù)給屬性賦值 -->
  <jsp:setProperty name="myUsers" property="username"/>
  <jsp:setProperty name="myUsers" property="password" param="mypass"/>
  <!-- 使用傳統(tǒng)的表達(dá)式方式來(lái)獲取用戶名和密碼 -->
  <%--  
    用戶名:<%=myUsers.getUsername() %><br>
    密碼:<%=myUsers.getPassword() %><br>
  --%>
  <!-- 使用getProperty方式來(lái)獲取用戶名和密碼 -->
   用戶名:<jsp:getProperty name="myUsers" property="username"/> <br>
   密碼:<jsp:getProperty name="myUsers" property="password"/><br>
  <br>
  <br>
 
   <a href="testScope.jsp" rel="external nofollow" >測(cè)試javabean的四個(gè)作用域范圍</a>
 
   <%
     request.getRequestDispatcher("testScope.jsp").forward(request, response);
   %>
 
 </body>
</html>

3、testScope.jsp

<%@ page language="java" import="java.util.*"
    contentType="text/html; charset=utf-8"%>
<%@ page import="com.po.Users"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
 
<title>My JSP 'testScope.jsp' starting page</title>
 
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
    <link rel="stylesheet" type="text/css" href="styles.css" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
    -->
 
</head>
 
<body>
    <h1>Javabean的四個(gè)作用域范圍</h1>
    <hr>
    <jsp:useBean id="myUsers" class="com.po.Users" scope="page" />
    用戶名:<jsp:getProperty name="myUsers" property="username" /><br> 密碼:<jsp:getProperty
        name="myUsers" property="password" /><br>
    <!-- 使用內(nèi)置對(duì)象獲取用戶名和密碼 -->
    <hr>
    <%--
    用戶名:<%=((Users)application.getAttribute("myUsers")).getUsername()%><br>
    密碼:<%=((Users)application.getAttribute("myUsers")).getPassword() %><br>
  --%>
    <%--
    用戶名:<%=((Users)session.getAttribute("myUsers")).getUsername()%><br>
    密碼:<%=((Users)session.getAttribute("myUsers")).getPassword() %><br>
  --%>
    <%--
    用戶名:<%=((Users)request.getAttribute("myUsers")).getUsername()%><br>
    密碼:<%=((Users)request.getAttribute("myUsers")).getPassword() %><br>
  --%>
    <%
        String username = "";
        String password = "";
        if (pageContext.getAttribute("myUsers") != null) {
            username = ((Users) pageContext.getAttribute("myUsers"))
                    .getUsername();
            password = ((Users) pageContext.getAttribute("myUsers"))
                    .getPassword();
        }
    %>
 
    用戶名:<%=username%><br> 密碼:<%=password%><br>
 
 
 
</body>
</html>
 

四 測(cè)試結(jié)果

 如有疑問(wèn)請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

  • Java實(shí)現(xiàn)向數(shù)組里添加元素

    Java實(shí)現(xiàn)向數(shù)組里添加元素

    這篇文章主要介紹了Java實(shí)現(xiàn)向數(shù)組里添加元素方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-11-11
  • java之this關(guān)鍵字用法實(shí)例分析

    java之this關(guān)鍵字用法實(shí)例分析

    這篇文章主要介紹了java之this關(guān)鍵字用法實(shí)例分析,較為詳細(xì)的講述了Java中this關(guān)鍵字的用法及適用范圍,并附帶實(shí)例程序加以說(shuō)明,需要的朋友可以參考下
    2014-09-09
  • java基礎(chǔ)之Collection與Collections和Array與Arrays的區(qū)別

    java基礎(chǔ)之Collection與Collections和Array與Arrays的區(qū)別

    這篇文章主要介紹了java基礎(chǔ)之Collection與Collections和Array與Arrays的區(qū)別的相關(guān)資料,本文主要說(shuō)明兩者的區(qū)別以防大家混淆概念,需要的朋友可以參考下
    2017-08-08
  • Java Redis Redisson配置教程詳解

    Java Redis Redisson配置教程詳解

    這篇文章主要介紹了Java Redis Redisson配置教程,包括Session共享配置及其他Redisson的Config配置方式,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-08-08
  • Spring使用@Value注解與@PropertySource注解加載配置文件操作

    Spring使用@Value注解與@PropertySource注解加載配置文件操作

    這篇文章主要介紹了Spring使用@Value注解與@PropertySource注解加載配置文件操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-06-06
  • java 動(dòng)態(tài)增加定時(shí)任務(wù)示例

    java 動(dòng)態(tài)增加定時(shí)任務(wù)示例

    本篇文章主要介紹了java 動(dòng)態(tài)增加定時(shí)任務(wù)示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-03-03
  • SpringSecurity 測(cè)試實(shí)戰(zhàn)

    SpringSecurity 測(cè)試實(shí)戰(zhàn)

    這篇文章主要介紹了SpringSecurity 測(cè)試實(shí)戰(zhàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • Java之進(jìn)程和線程的區(qū)別

    Java之進(jìn)程和線程的區(qū)別

    這篇文章主要介紹了進(jìn)程與線程的區(qū)別,線程具有許多傳統(tǒng)進(jìn)程所具有的特征,而把傳統(tǒng)的進(jìn)程稱為重型進(jìn)程(Heavy—Weight Process),它相當(dāng)于只有一個(gè)線程的任務(wù),有感興趣的小伙伴可以參考閱讀本文
    2023-03-03
  • 關(guān)于SpringBoot使用Redis空指針的問(wèn)題(不能成功注入的問(wèn)題)

    關(guān)于SpringBoot使用Redis空指針的問(wèn)題(不能成功注入的問(wèn)題)

    這篇文章主要介紹了關(guān)于SpringBoot使用Redis空指針的問(wèn)題(不能成功注入的問(wèn)題),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-11-11
  • Java?WorkBook對(duì)Excel的基本操作方法

    Java?WorkBook對(duì)Excel的基本操作方法

    這篇文章主要介紹了Java?WorkBook對(duì)Excel的基本操作方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-03-03

最新評(píng)論

嘉善县| 新龙县| 台北县| 察雅县| 昂仁县| 西宁市| 万年县| 商河县| 建始县| 太保市| 双鸭山市| 东乡族自治县| 夏河县| 万宁市| 昆山市| 武义县| 北辰区| 元朗区| 延长县| 忻城县| 屏东市| 滨州市| 西丰县| 静宁县| 舞阳县| 古田县| 北辰区| 莱芜市| 三门县| 西城区| 阿勒泰市| 仪征市| 手游| 浦北县| 保定市| 辽阳县| 徐闻县| 台南县| 西林县| 宁远县| 日喀则市|