网站建设资讯

NEWS

网站建设资讯

在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> <br> 网页题目:在JSP编程中Application的使用方法详解 <br> URL分享:<a href="http://cdysf.com/article/dpicjih.html">http://cdysf.com/article/dpicjih.html</a> </div> </div> <div class="other"> <h3>其他资讯</h3> <ul> <li> <a href="/article/cocgdio.html">实用的shell脚本</a> </li><li> <a href="/article/cocgojg.html">Java面试被问到Dubbo,怎么回答可以得高分?</a> </li><li> <a href="/article/cocgdes.html">为什么绿钻那么难升级</a> </li><li> <a href="/article/cocgdog.html">美国网站服务器登陆IP地址保存多久有效</a> </li><li> <a href="/article/cocgdds.html">租用香港服务器的技巧是什么</a> </li> </ul> </div> </div> </div> <footer> <div class="footop"> <div class="wrap"> <div class="bottomrpw"> <div class="erp arp"> <dl> <dt>ADDRESS</dt> <dd class="address"> <i class="icon"></i> <span class="word">成都市青羊区锦天国际1号楼1002室</span> </dd> </dl> </div> <div class="erp arp"> <dl> <dt>TEL</dt> <dd class="phonum"> <i class="icon"></i> <span class="word en"> <a href="tel:18980820575">18980820575</a> </span> </dd> </dl> </div> <div class="erp crp"> <dl> <dt>OTHER</dt> <dd> <a class="word get-quote">获得报价与方案</a> </dd> <dd> <a href="#" target="_blank" rel='nofollow' class="word" title="付款方式">付款方式</a> </dd> </dl> </div> <div class="erp code-rp"> <dl> <dt>Wechat</dt> <dd class="code-wrap"> <span class="code"> <img src="/Public/Home/images/qr-code.jpg" alt="创帆新辰微信公众号" /> </span> </dd> </dl> </div> </div> </div> </div> <div class="footerbot"> <div class="friendlinks"> <div class="wrap"> <ul class="rpl"> <li><a href="http://www.bcwzsj.com/" title="bcwzsj.com" target="_blank">bcwzsj.com</a></li><li><a href="http://www.scfushun.com/" title="富顺网站建设" target="_blank">富顺网站建设</a></li><li><a href="http://www.lqfdjxw.com/" title="龙泉发电机维修" target="_blank">龙泉发电机维修</a></li><li><a href="http://www.scxinheng.cn/" title="信衡房屋鉴定" target="_blank">信衡房屋鉴定</a></li><li><a href="https://www.cdcxhl.com/" title="创新互联" target="_blank">创新互联</a></li><li><a href="http://www.shufengxianlan.com/" title="shufengxianlan.com" target="_blank">shufengxianlan.com</a></li><li><a href="http://www.tjxishu.com/" title="成都柴油发电机租用" target="_blank">成都柴油发电机租用</a></li><li><a href="https://www.cdxwcx.com/wangzhan/h5.html" title="h5响应式网站" target="_blank">h5响应式网站</a></li><li><a href="http://m.cdcxhl.cn/seo/ " title="成都网站优化" target="_blank">成都网站优化</a></li><li><a href="http://www.zgyiwo.cn/" title="普特斯腐植酸" target="_blank">普特斯腐植酸</a></li> </ul> </div> </div> <div class="wrap"> <div class="copyright"> <span class="en">©2007-2025</span> 青羊区创帆新辰信息咨询服务部(个体工商户) <span class="en">ALL RIGHTS RESERVED.</span> <a rel="nofollow" href="http://www.miitbeian.gov.cn" target="_blank">蜀ICP备2025128472号</a> </div> </div> </div> </footer> <div class="fcwrap"> <ul class="rpl clearfix"> <li class="phone"> <a rel="nofollow" target="_blank" href="tel:18980820575"> <i class="icon"></i> <strong>18980820575</strong> </a> </li> <li class="qq"> <a rel="nofollow" target="_blank" href="https://wpa.qq.com/msgrd?v=1&uin=244261566&site=qq&menu=yes"> <i class="icon"></i> <strong>244261566</strong> </a> </li> <li class="back-top"> <a href="javascript:void(0)" rel="nofollow" class="back-to-top"> <i class="icon"></i> <strong>回到顶部</strong> </a> </li> </ul> </div> <!--nav--> <div class="n-Wrap"> <div class="navBar visble show"> <div class="barlogo"> <a href="/" rel="nofollow"> <img src="/Public/Home/images/logo1.png" alt="成都做网站" /> <img src="/Public/Home/images/logo2.png" alt="成都网站设计" /> </a> </div> <div class="bmenu"> <i class="bar-top"><span></span></i> <i class="bar-cen"><span></span></i> <i class="bar-bom"><span></span></i> <i class="bar-left"><span></span></i> <i class="bar-right"><span></span></i> </div> </div> <section class="fixmenu"> <div class="close-bar"> <i class="bar-left"><span></span></i> <i class="bar-right"><span></span></i> </div> <nav class="smph"> <ul> <li class="index-hrefs on"><a href="http://www.cdysf.com/"><font>首页</font></a></li> <li><a href="/about/" rel="nofollow"><font>关于我们</font></a></li> <li><a href="/service/" rel="nofollow"><font>网站建设</font></a></li> <li><a href="/case/" rel="nofollow"><font>网站案例</font></a></li> <li><a href="/solve/" rel="nofollow"><font>网站方案</font></a></li> <li><a href="/news/" rel="nofollow"><font>建站知识</font></a></li> <li><a href="/contact/" rel="nofollow"><font>联系创帆新辰</font></a></li> </ul> <div class="pwrap"> <span class="label">建站热线</font> <strong class="phone"><a href="tel:18980820575">18980820575</a></strong> </div> </nav> </section> </div> <!--end nav--> <script src="/Public/Home/js/hotcss.js"></script> <script type="text/javascript" src="/Public/Home/js/su_new.js"></script> </body> </html> <script> $(".con img").each(function(){ var src = $(this).attr("src"); //获取图片地址 var str=new RegExp("http"); var result=str.test(src); if(result==false){ var url = "https://www.cdcxhl.com"+src; //绝对路径 $(this).attr("src",url); } }); window.onload=function(){ document.oncontextmenu=function(){ return false; } } </script>