最新更新 sitemap 网站制作设计本站搜索
网页设计
国外网站 韩国网站 个人主页 手提袋设计 CSS 网页特效 平面设计 网站设计 Flash CMS技巧 服装网站 php教程 photoshop 画册 服务器选用 数据库 Office
虚拟主机 域名注册 云主机 网页设计 客服QQ:8208442
当前位置:首页 > 编程开发 > jsp教程

jsp编程:关于JSP中JavaBean的Scope属性

日期:10-15    来源:中国设计秀    作者:cnwebshow.com

测试application和request:36W中国设计秀

1.包:36W中国设计秀

package ScopeTest;36W中国设计秀

/**36W中国设计秀
 *36W中国设计秀
 * @author lucifer36W中国设计秀
 */36W中国设计秀
public class TestScope {36W中国设计秀
     PRivate int i;36W中国设计秀
     public TestScope(){36W中国设计秀
          i = 0;36W中国设计秀
     }36W中国设计秀
     public int getNextInt(){36W中国设计秀
          return ++i;36W中国设计秀
     }36W中国设计秀
}36W中国设计秀

2.jsp代码:36W中国设计秀

<%-- 36W中国设计秀
    Document   : TestScope36W中国设计秀
    Created on : 2009-10-3, 14:29:1836W中国设计秀
    Author     : lucifer36W中国设计秀
--%>36W中国设计秀

<%@page contentType="text/html" pageEncoding="UTF-8"%>36W中国设计秀
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"36W中国设计秀
   "http://www.w3.org/TR/html4/loose.dtd">36W中国设计秀

36W中国设计秀
<jsp:useBean id="reqScope" class="ScopeTest.TestScope" scope="request"/>36W中国设计秀
<jsp:useBean id="appScope" class="ScopeTest.TestScope" scope="application"/>36W中国设计秀
<html>36W中国设计秀
    <head>36W中国设计秀
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">36W中国设计秀
        <title>JSP Page</title>36W中国设计秀
    </head>36W中国设计秀
    <body>36W中国设计秀
        Application Scope:36W中国设计秀
        <jsp:getProperty name="appScope" property="nextInt"/>36W中国设计秀
        <br>36W中国设计秀
        Request Scope:36W中国设计秀
        <jsp:getProperty name="reqScope" property="nextInt"/>36W中国设计秀
        <form method="get" action="TestScope.jsp">36W中国设计秀
               <input type="submit" value="Reget">36W中国设计秀
        </form>36W中国设计秀
    </body>36W中国设计秀
</html>36W中国设计秀

3.输出:36W中国设计秀

Application Scope: 1 36W中国设计秀
Request Scope: 136W中国设计秀

 36W中国设计秀
按下按钮后输出:36W中国设计秀

Application Scope: 236W中国设计秀
Request Scope: 136W中国设计秀

本文引用地址:/bc/article_46570.html
网站地图 | 关于我们 | 联系我们 | 网站建设 | 广告服务 | 版权声明 | 免责声明