在JSP编程中Application的使用方法详解

JSP调用Javeabean命令UseBean中有Scope设置,一般有 Application session page等设置,Page就是每页重新产生usebean中的javabean新对象,一般情况是用这种,如果多个JSP程序间为共享数据,可以使用 session

在紫阳等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站设计、网站建设 网站设计制作按需定制网站,公司网站建设,企业网站建设,品牌网站建设,全网营销推广,外贸网站制作,紫阳网站建设费用合理。

而application的意思,该javabean将一直存在,与session相对用户来说,application是相对应用程序的,一般来说,一个用户有一个session,并且随着用户离开而消失;而application则是一直存在,类似一个servlet程序,类似整个系统的"全局变量",而且只有一个实例。

MVC中控制功能

因此application这个特性,很适合用来做MVC中的控制功能,一般传统MVC是用servlet做控制功能,V基本是JSP页面,M就是中间件Javabean之类。

但是随着JSP功能的完善和推广,逐渐有替代servlet之趋势,我们在实践中更多使用的也是JSP,有时为了省却麻烦的事情,就使用JSP代替servlet.尤其是其控制功能。

实际上,这个控制功能是封装在一个Javabean中,JSP使用scope=application来调用这个Javabean,这样,具备控制功能的javabean就类似servlet常驻内存,并和后台各种中间件交互操作。

“首页”的展现

在实际应用中,我们经常有多个用户要同时访问一个页面,如首页,这个首页中有很多功能要运行,比如目录分类,首页程序要从数据库中读入树形数据并展开,输出到首页,这个功能是封装在Javabean中的。

那么首页JSP调用这个Javabean时,使用scope=application, 再通过树形数据的缓冲算法,这样,多个用户同时访问首页时,首页JSP就无需每次启动Javabean然后再反复读取数据库了。无疑大大提高速度。

所以如果你的首页JSP访问量很高,那么就应该在这方面多花点时间优化。

数据库连接缓冲

 
 
 
  1.  id="cods" 
  2.   class="oracle.jdbc.pool.OracleConnectionCacheImpl"  
  3.   scope="application" /> 
  4.  
  5. <%  
  6. cods.setURL("jdbc:oracle:thin:@HOST:PORT:SID"); 
  7. cods.setUser("scott"); 
  8. cods.setPassword("tiger"); 
  9. cods.setStmtCache (5);  
  10. %> 
  11. event:application_OnStart> 
  12. <%@ page import="java.sql.*, javax.sql.*, oracle.jdbc.pool.*" %> 
  13. * This is a JavaServer Page that uses Connection Caching over 
  14. application 
  15. * scope. The Cache is created in an application scope in 
  16. globals.jsa file.  
  17. * Connection is obtained from the Cache and recycled back once 
  18. done. 
  19.   
  20.   
  21. </strong>  </li> <li>ConnCache JSP  </li> <li><strong> TITLE></strong>  </li> <li><strong> HEAD></strong>  </li> <li><strong><BODY</strong> BGCOLOR=EOFFFO<strong>></strong>   </li> <li><strong><H1></strong> Hello   </li> <li><strong><</strong>%= (request.getRemoteUser() != null? ", " +  </li> <li>request.getRemoteUser() : "") %<strong>></strong>  </li> <li>! I am Connection Caching JSP.  </li> <li><strong> H1></strong>  </li> <li><strong><HR></strong>  </li> <li><strong><B></strong> I get the Connection from the Cache and recycle it back.  </li> <li><strong> B></strong>   </li> <li><strong><P></strong>  </li> <li><strong><</strong>%  </li> <li>try {  </li> <li>Connection conn = cods.getConnection();  </li> <li>Statement stmt = conn.createStatement ();  </li> <li>ResultSet rset = stmt.executeQuery ("SELECT ename, sal " +   </li> <li>"FROM scott.emp ORDER BY ename");  </li> <li>if (rset.next()) {  </li> <li>%<strong>></strong>  </li> <li><strong><TABLE</strong> BORDER=1 BGCOLOR="C0C0C0"<strong>></strong>  </li> <li><strong><TH</strong> WIDTH=200 BGCOLOR="white"<strong>></strong> <strong><I></strong>Employee Name<strong> I></strong> <strong> TH></strong>  </li> <li><strong><TH</strong> WIDTH=100 BGCOLOR="white"<strong>></strong> <strong><I></strong>Salary<strong> I></strong> <strong> TH></strong>  </li> <li><strong><TR></strong> <strong><TD</strong> ALIGN=CENTER<strong>></strong> <strong><</strong>%= rset.getString(1) %<strong>></strong> <strong> TD></strong>  </li> <li><strong><TD</strong> ALIGN=CENTER<strong>></strong> $<strong><</strong>%= rset.getDouble(2) %<strong>></strong> <strong> TD></strong>  </li> <li><strong> TR></strong>  </li> <li><strong><</strong>% while (rset.next()) {  </li> <li>%<strong>></strong>  </li> <li><strong><TR></strong> <strong><TD</strong> ALIGN=CENTER<strong>></strong> <strong><</strong>%= rset.getString(1) %<strong>></strong> <strong> TD></strong>  </li> <li><strong><TD</strong> ALIGN=CENTER<strong>></strong> $<strong><</strong>%= rset.getDouble(2) %<strong>></strong> <strong> TD></strong>  </li> <li><strong> TR></strong>  </li> <li><strong><</strong>% }  </li> <li>%<strong>></strong>  </li> <li><strong> TABLE></strong>  </li> <li><strong><</strong>% }   </li> <li>else {  </li> <li>%<strong>></strong>  </li> <li><strong><P></strong> Sorry, the query returned no rows! <strong> P></strong>  </li> <li><strong><</strong>%   </li> <li>}  </li> <li>rset.close();  </li> <li>stmt.close();  </li> <li>conn.close(); // Put the Connection Back into the Pool  </li> <li>} catch (SQLException e) {  </li> <li>out.println("<strong><P></strong>" + "There was an error doing the query:");  </li> <li>out.println ("<strong><PRE></strong>" + e + "<strong> PRE></strong> n <strong><P></strong>");  </li> <li>}  </li> <li>%<strong>></strong>  </li> <li><strong> BODY></strong>  </li> <li><strong> HTML></strong></li> </ol></pre></p> <p> 网站栏目:<a href="http://www.csdahua.cn/qtweb/news24/155624.html">在JSP编程中Application的使用方法详解</a> <br> 标题网址:<a href="http://www.csdahua.cn/qtweb/news24/155624.html">http://www.csdahua.cn/qtweb/news24/155624.html</a> </p> <p> 网站建设、网络推广公司-快上网,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等 </p> <p class="adpic"> <a href="https://www.cdcxhl.com/service/ad.html" target="_blank" class="ad">广告</a> <a href="" target="_blank" class="adimg"><img src=""></a> </p> <p class="copy"> 声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: <a href="http://www.csdahua.cn/" target="_blank">快上网</a> </p> </div> <div class="newsmorelb"> <p>成都快上网为您推荐相关内容</p> <ul> <li> <a href="/qtweb/news23/155623.html">搭建mysql服务器怎么优化</a> </li><li> <a href="/qtweb/news22/155622.html">我准备开发个APP,服务器需要什么样的配置?专用服务器可以搭建app吗</a> </li><li> <a href="/qtweb/news21/155621.html">香港虚拟主机与香港VPS、香港服务器有何区别呢?</a> </li><li> <a href="/qtweb/news20/155620.html">RazerWindows外设驱动安全漏洞已波及SteelSeries</a> </li><li> <a href="/qtweb/news19/155619.html">win10适配手机机型?windows10phone安卓</a> </li><li> <a href="/qtweb/news18/155618.html">秒杀抢购,利用Redis轻松实现(利用redis实现抢购)</a> </li><li> <a href="/qtweb/news17/155617.html">windows7用户不见了怎么办?(win7用户没了)</a> </li><li> <a href="/qtweb/news16/155616.html">备案执照不在身边有照片可以上传吗手机没法操作</a> </li><li> <a href="/qtweb/news15/155615.html">创新互联MinecraftWiki教程:在末地生存的优劣[]</a> </li> </ul> </div> </div> <div class="col-lg-3 noneb"> <div class="bkright" style="margin-top: 0"> <p><a href="https://www.cdcxhl.com/news/daohang/">网站导航知识</a></p> <ul> <li> <a class="text_overflow" href="/qtweb/news5/277005.html">比较万网主机和阿里云主机,看哪个更出色(万网主机和阿里云主机谁比较好)</a> </li><li> <a class="text_overflow" href="/qtweb/news18/220118.html">中兴智能机顶盒设置,联通中兴机顶盒怎么设置啊</a> </li><li> <a class="text_overflow" href="/qtweb/news36/66836.html">服务器主机叫什么东西?(服务器主机叫什么东西名字)</a> </li><li> <a class="text_overflow" href="/qtweb/news21/526121.html">sqlserver存储过程分页总结</a> </li><li> <a class="text_overflow" href="/qtweb/news31/194431.html">为什么传文件会失效</a> </li><li> <a class="text_overflow" href="/qtweb/news4/355254.html">常用五大MySQL维护管理工具列举</a> </li><li> <a class="text_overflow" href="/qtweb/news47/103547.html">html的图片如何移动</a> </li><li> <a class="text_overflow" href="/qtweb/news18/343818.html">讯飞输入法电脑版去哪下载_讯飞输入法有哪些特色</a> </li><li> <a class="text_overflow" href="/qtweb/news49/533999.html">查看redis配置生效时间的技巧(查询redis生效时间)</a> </li><li> <a class="text_overflow" href="/qtweb/news38/421088.html">Linux C编程实战:XML应用(linuxcxml)</a> </li><li> <a class="text_overflow" href="/qtweb/news43/424193.html">Php.ini设置:filter.default</a> </li><li> <a class="text_overflow" href="/qtweb/news3/371303.html">如何安装服务器系统?一步步教你安装服务器系统</a> </li><li> <a class="text_overflow" href="/qtweb/news33/299183.html">Linux如何查看iptables状态和重启</a> </li><li> <a class="text_overflow" href="/qtweb/news33/116783.html">怎么加伊春信息平台?(伊春网站建设公司)</a> </li><li> <a class="text_overflow" href="/qtweb/news27/79777.html">云虚拟机管理的方法有哪些</a> </li> </ul> </div> <div class="bkright tag"> <p><a href="https://www.cdcxhl.com/hangye/" target="_blank">分类信息网</a></p> <ul> <li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/sclsb/" target="_blank">水处理设备</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/chayisj/" target="_blank">茶艺设计</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/weilanhulan/" target="_blank">围栏护栏</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/shidiao/" target="_blank">石雕</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/zkj/" target="_blank">公路钻孔机</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/geshan/" target="_blank">格栅板</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/hgdsj/" target="_blank">火锅店设计</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/ldjbc/" target="_blank">履带搅拌车</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/jiagu/" target="_blank">加固</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/shipindai/" target="_blank">食品包装袋</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/bengche/" target="_blank">混凝土泵车</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/shilongwang/" target="_blank">石笼网</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/zdfhw/" target="_blank">主动防护网</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/chalousj/" target="_blank">茶楼设计</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/yhjdsj/" target="_blank">宴会酒店设计</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/chunshuiji/" target="_blank">纯水机</a> </li> </ul> </div> </div> </div> <div class="carousel-inner linkbg" style="background: #fff"> <div class="container"> <a href="http://m.cdcxhl.com/" target="_blank">成都网站设计</a>    <a href="http://www.myzwz.com/" target="_blank">绵阳网站建设</a>    <a href="https://www.cdxwcx.com/cloud/" target="_blank">成都云服务器</a>    <a href="https://www.cdxwcx.com/city/guangan/" target="_blank">广安网站建设</a>    <a href="http://www.cdxwcx.cn/" target="_blank">做网站</a>    <a href="http://m.cdxwcx.com/tuoguan.html" target="_blank">成都服务器托管</a>    <a href="http://www.cdfuwuqi.com/host/" target="_blank">虚拟主机</a>    <a href="http://www.snfdjwx.com/" target="_blank">成都企业注册服务</a>    <a href="http://www.2518874.com/" target="_blank">王君美油画</a>    <a href="http://www.scpengan.com/" target="_blank">蓬安网站建设</a>    <a href="http://www.scarg.cn/" target="_blank">成都艾瑞格</a>    <a href="http://www.scjiangyou.cn/" target="_blank">江油网站建设</a>    <a href="http://m.cdcxhl.cn/qiye/ " target="_blank">企业网站建设</a>    <a href="http://www.ruijiemsc.com/" target="_blank">瑞杰企业管理</a>    <a href="https://www.cdcxhl.com/tuoguan/yidong/" target="_blank">成都移动服务器托管</a>    <a href="https://www.cdcxhl.com/app.html" target="_blank">成都app软件开发</a>    <a href="http://www.bcwzsj.com/" target="_blank">成都广告安装公司</a>    <a href="http://www.xjjierui.cn/" target="_blank">新津网站运维</a>    <a href="http://www.bzwzjz.com/serve/" target="_blank">高端网站建设</a>    <a href="http://www.njzdgg.com/" target="_blank">支点广告</a>     </div> </div> <footer> <div class="carousel-inner footjz"> <div class="container"> <i class="icon iconfont zbw"></i> 高品质定制 <i class="icon iconfont"></i> 跨终端自动兼容 <i class="icon iconfont"></i> 节约开发成本 <i class="icon iconfont"></i> 开发周期短 <i class="icon iconfont"></i> 一体化服务 <button type="button" class="btn btn-default btn-lg" onClick="window.location.href='tencent://message/?uin=631063699&Site=&Menu=yes'"> 立即开始2800定制网站建设</button> <button type="button" class="btn btn-default btn-xs" onClick="window.location.href='tencent://message/?uin=631063699&Site=&Menu=yes'"> 2800定制网站建设</button> </div> </div> <div class="carousel-inner bqsy"> <div class="container"> <div class="lxfs"> <h4 class="yutelnone">028-86922220 13518219792</h4> <h4 class="yutelblock"><a href="tel:02886922220">028-86922220</a> <a href="tel:13518219792">13518219792</a></h4> <a class="btn btn-default" href="tencent://message/?uin=532337155&Site=&Menu=yes" role="button">网站建设<span>QQ</span>:532337155</a> <a class="btn btn-default" href="tencent://message/?uin=631063699&Site=&Menu=yes" role="button">营销推广<span>QQ</span>:631063699</a> <a class="btn btn1 btn-default" href="mqqwpa://im/chat?chat_type=wpa&uin=532337155&version=1&src_type=web&web_src=oicqzone.com" role="button">网站制作<span>QQ</span>:532337155</a> <a class="btn btn1 btn-default" href="mqqwpa://im/chat?chat_type=wpa&uin=631063699&version=1&src_type=web&web_src=oicqzone.com" role="button">营销推广<span>QQ</span>:631063699</a> <a class="btn btn-default nonea" href="tencent://message/?uin=1683211881&Site=&Menu=yes" role="button">售后QQ:1683211881</a> <div class="dz">成都快上网专注: <a href="http://www.csdahua.cn/" target="_blank">网站优化</a> <a href="http://www.csdahua.cn/" target="_blank">网络推广</a> <a href="http://www.csdahua.cn/" target="_blank">网站建设</a> <address>地址:成都太升南路288号锦天国际A幢10楼</address> </div> </div> <div class="bzdh dz"><img src="https://www.cdcxhl.com/imges/bottom_logo.png" alt="创新互联"> <p><a href="https://www.cdcxhl.com/menu.html" target="_blank">成都创新互联科技有限公司</a><br> Tel:028-86922220(7x24h)</p></div> </div> </div> </footer> </body> </html> <script> $.getJSON ("../../qtwebpic.txt", function (data) { var jsonContent = { "featured":data } var random = jsonContent.featured[Math.floor(Math.random() * jsonContent.featured.length)]; $(".adpic .adimg").attr("href",random.link) $(".adpic img").attr("src",random.pic); }) </script>