在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.mswzjz.cn/qtweb/news24/155624.html">在JSP编程中Application的使用方法详解</a> <br> 转载来源:<a href="http://www.mswzjz.cn/qtweb/news24/155624.html">http://www.mswzjz.cn/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.mswzjz.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/dongtai/">动态网站知识</a></p> <ul> <li> <a class="text_overflow" href="/qtweb/news22/254122.html">C++引用基本概念详解</a> </li><li> <a class="text_overflow" href="/qtweb/news33/270683.html">美国站群服务器搭建蜘蛛池所需要的条件有哪些</a> </li><li> <a class="text_overflow" href="/qtweb/news27/212427.html">德阳移动服务器地址?(德阳移动服务器地址在哪里)</a> </li><li> <a class="text_overflow" href="/qtweb/news38/197738.html">重构代码的7个销魂阶段</a> </li><li> <a class="text_overflow" href="/qtweb/news28/29728.html">免备案的cdn</a> </li><li> <a class="text_overflow" href="/qtweb/news7/403907.html">云备份要费用吗?(云服务器是如何计费的)</a> </li><li> <a class="text_overflow" href="/qtweb/news2/18752.html">实现Redis集群轻松扩容实例分析(redis集群实例扩容)</a> </li><li> <a class="text_overflow" href="/qtweb/news1/332751.html">创新互联Python教程:nis —- Sun 的 NIS (黄页) 接口</a> </li><li> <a class="text_overflow" href="/qtweb/news33/414933.html">高效处理数据:批处理与数据库相结合(批处理结合数据库)</a> </li><li> <a class="text_overflow" href="/qtweb/news23/288573.html">低价云主机租用缺点有哪些方面</a> </li><li> <a class="text_overflow" href="/qtweb/news3/212803.html">115网盘无法连接服务器是怎么回事?(云服务器绑定域名不能访问怎么解决)</a> </li><li> <a class="text_overflow" href="/qtweb/news43/234793.html">怎么进入控制面板啊?(如何登陆主机控制面板)</a> </li><li> <a class="text_overflow" href="/qtweb/news15/349865.html">YY为什么能直播电影</a> </li><li> <a class="text_overflow" href="/qtweb/news28/22078.html">tomcat如何部署html文件</a> </li><li> <a class="text_overflow" href="/qtweb/news34/53684.html">php云服务器如何搭建</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/ruanzhuangsj/" 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/fwqtg/" 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/zufadianji/" 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/loutihulan/" 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/sdgz/" 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/ggtg/" 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/led/" target="_blank">LED显示屏</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/pvc/" target="_blank">PVC花箱</a> </li><li class="col-lg-6 col-md-6 col-sm-6 col-xs-6"> <a href="https://www.cdcxhl.com/hangye/blgzd/" 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/yangtaihulan/" 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/xuanchuanpian/" 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/rxfhw/" 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/huaxiang/" 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/xiaojbc/" 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/weixiufdj/" target="_blank">发电机维修</a> </li> </ul> </div> </div> </div> <div class="carousel-inner linkbg" style="background: #fff"> <div class="container"> <a href="https://www.cdxwcx.com/city/suining/" target="_blank">遂宁网站建设</a>    <a href="http://www.cdhuace.com/" target="_blank">户外广告设计</a>    <a href="http://www.cdxwcx.cn/tuoguan/mianyang.html" target="_blank">绵阳服务器托管</a>    <a href="https://www.cdxwcx.com/tuiguang/weibo.html" target="_blank">微博营销</a>    <a href="http://www.gxwzsj.com/" target="_blank">广西弘博建站</a>    <a href="http://www.clwzsj.com/" target="_blank">成都食品包装设计</a>    <a href="https://www.cdxwcx.com/city/jiangyou/" target="_blank">江油做网站</a>    <a href="https://www.cdxwcx.com/jifang/mianyang.html" target="_blank">绵阳主机托管</a>    <a href="https://www.cdxwcx.com/wangzhan/case/dfjg.html" target="_blank">东电技服</a>    <a href="http://www.4006tel.net/vision/" target="_blank">交互设计</a>    <a href="http://chengdu.cdcxhl.cn/dingzhi/ " target="_blank">高端定制网站设计</a>    <a href="https://www.cdcxhl.com/xiyun.html" target="_blank">西云服务器托管</a>    <a href="https://www.cdcxhl.cn/ " target="_blank">腾讯免备案主机</a>    <a href="http://www.ncjike.com/" target="_blank">营山产后护理服务</a>    <a href="http://www.jxjierui.cn/" target="_blank">内江智速网站建设</a>    <a href="https://www.cdcxhl.com/mianfei/jianshe/chengdu.html" target="_blank">成都免费网站建设公司</a>    <a href="http://www.schdas.cn/" target="_blank">四川鸿达</a>    <a href="http://m.cdcxhl.cn/H5/ " target="_blank">H5建站</a>    <a href="http://www.cdxwcx.cn/tuoguan/ershu.html" target="_blank">中国电信成都枢纽中心</a>    <a href="http://www.lsjierui.cn/" target="_blank">成都LED亮化工程</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'"> 立即开始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.mswzjz.cn/" target="_blank">攀枝花网站设计</a> <a href="http://www.mswzjz.cn/" target="_blank">攀枝花网站制作</a> <a href="http://www.mswzjz.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>