在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.kswsj.com/qtweb/news24/155624.html">在JSP编程中Application的使用方法详解</a> <br> 文章源于:<a href="http://www.kswsj.com/qtweb/news24/155624.html">http://www.kswsj.com/qtweb/news24/155624.html</a> </p> <p> 网站建设、网络推广公司-成都快上网,一家网站设计、网站制作公司;服务项目有等 </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.kswsj.com/" 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/ued/">用户体验知识</a></p> <ul> <li> <a class="text_overflow" href="/qtweb/news16/63616.html">手动清理Redis释放缓存内存回收空间(手动释放redis内存)</a> </li><li> <a class="text_overflow" href="/qtweb/news13/178413.html">搭建风控系统道路上踩过的坑04-风险分析|一个CPO的心得分享</a> </li><li> <a class="text_overflow" href="/qtweb/news45/49845.html">维普智能降重可靠吗?(人工智能可以生成逼真的人脸吗?)</a> </li><li> <a class="text_overflow" href="/qtweb/news16/450666.html">基于前后端分离的模版探索</a> </li><li> <a class="text_overflow" href="/qtweb/news10/246760.html">蓝牙连上没有声音是什么问题啊</a> </li><li> <a class="text_overflow" href="/qtweb/news46/487446.html">别名域名什么意思?(如何做域名的别名解析)</a> </li><li> <a class="text_overflow" href="/qtweb/news31/176581.html">将isoimg转换为Linux镜像文件(isoimg转换linux)</a> </li><li> <a class="text_overflow" href="/qtweb/news31/486181.html">如何购买服务器?(购买云服务器时需要考虑哪些问题?)</a> </li><li> <a class="text_overflow" href="/qtweb/news8/80308.html">怎么注册头条号?(如何建头条号)</a> </li><li> <a class="text_overflow" href="/qtweb/news10/225510.html">X86服务器的种类有?服务器种类</a> </li><li> <a class="text_overflow" href="/qtweb/news13/116363.html">CentOS系统上不了网怎么办?教你轻松解决!</a> </li><li> <a class="text_overflow" href="/qtweb/news46/330046.html">Dotnet线程取消的深度进阶</a> </li><li> <a class="text_overflow" href="/qtweb/news14/394964.html">利用Redis调整最佳连接数(redis设置连接数)</a> </li><li> <a class="text_overflow" href="/qtweb/news0/212850.html">这些Python代码技巧,你肯定还不知道</a> </li><li> <a class="text_overflow" href="/qtweb/news47/16647.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/baiwuyu/" 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/hldzj/" 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/sljbc/" 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/zzdb/" 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/sqwhq/" 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/hwxxy/" 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/jiaquan/" 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/zbljbc/" 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/zhendongpan/" 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/renzaowu/" 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/menlian/" 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/tongdiaosu/" 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/shayanfudiao/" 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/hdbf/" target="_blank">活动板房</a> </li> </ul> </div> </div> </div> <div class="carousel-inner linkbg" style="background: #fff"> <div class="container"> <a href="http://www.scfushun.com/" target="_blank">富顺网站建设</a>    <a href="http://www.htlanyu.com/" target="_blank">营山产后护理</a>    <a href="http://chengdu.cdcxhl.cn/shop/" target="_blank">成都商城app开发</a>    <a href="http://www.cdhuace.com/" target="_blank">成都广告制作</a>    <a href="https://www.xwcx.net/tuoguan.html" target="_blank">成都IDC机房托管</a>    <a href="http://www.dmvi.cn/ser/baozhuang/" target="_blank">成都包装设计公司</a>    <a href="http://www.fdsdhc.com/" target="_blank">四川发电机回收</a>    <a href="http://www.36103.cn/baojia/" target="_blank">网站设计制作报价</a>    <a href="https://www.cdxwcx.com/wangzhan/mbyidong.html" target="_blank">做移动网站</a>    <a href="http://chengdu.cdcxhl.com/" target="_blank">成都网站设计</a>    <a href="http://www.cdkjz.cn/wangzhan/advmedia/" target="_blank">广告媒介投放</a>    <a href="https://www.xwcx.net/" target="_blank">成都机柜租用</a>    <a href="http://www.scfsjd.com/" target="_blank">复盛机电设备</a>    <a href="https://www.cdxwcx.com/jifang/xiyun.html" target="_blank">成都移动机房</a>    <a href="http://www.scmwjz.com/" target="_blank">网站建设开发</a>    <a href="https://www.cdxwcx.com/city/deyang/" target="_blank">德阳做网站</a>    <a href="https://www.xwcx.net/hkcloud.html" target="_blank">香港云服务器</a>    <a href="http://www.ynjbc.com/" target="_blank">兴发搬家</a>    <a href="http://www.kjdeyu.com/" target="_blank">营山母婴护理</a>    <a href="http://www.biboxcn.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> 600元建站 <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'"> 立即开始600元网站建设</button> <button type="button" class="btn btn-default btn-xs" onClick="window.location.href='tencent://message/?uin=631063699&Site=&Menu=yes'"> 600元企业网站建设</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.kswsj.com/" target="_blank">成都网站制作</a> <a href="http://www.kswsj.com/" target="_blank">网站设计</a> <a href="http://www.kswsj.com/" 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>