成都网站建设设计

将想法与焦点和您一起共享

在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> 转载注明:<a href="http://chengdu.cdxwcx.cn/article/dpicjih.html">http://chengdu.cdxwcx.cn/article/dpicjih.html</a> </div> </div> </div> <!--左边end--> <!--右边begin--> <div class="news_r"> <div class="news_t"><h2 class="h2">其他资讯</h2></div> <div class="news_ul3"> <ul> <li> <a href="/article/cddpdee.html"> <h3 class="h3">JavaScriptArray对象用法速查手册</h3> </a> </li><li> <a href="/article/cddpdce.html"> <h3 class="h3">mongodb数据导入和导出</h3> </a> </li><li> <a href="/article/cddpohh.html"> <h3 class="h3">编译服务器租用?(编译服务器租用什么)</h3> </a> </li><li> <a href="/article/cddpdsi.html"> <h3 class="h3">阜新小程序开发</h3> </a> </li><li> <a href="/article/cddpohd.html"> <h3 class="h3">SQLServer2008数据库的报表服务的相关信息</h3> </a> </li> </ul> </div> </div> <!--右边end--> <div class="c_l"></div> </div> </div> <!--正文end--> <!--尾部begin--> <!--尾部begin--> <footer> <div class="f_bg"> <div class="wrap"> <div class="links"> <h2 class="h2">甜橘子解决方案<a href="/solution/" title="更多" class="more">更多+</a></h2> <ul> <li><a href="/solution/xiaochengxu.html" title="小程序定制解决方案">小程序定制解决方案</a></li> <li><a href="/solution/qiyewz.html" title="企业网站建设解决方案">企业网站建设解决方案</a></li> <li><a href="/solution/menhuwz.html" title="行业门户网站建设解决方案">行业门户网站建设解决方案</a></li> <li><a href="/solution/yingxiaowz.html" title="营销型网站建设解决方案">营销型网站建设解决方案</a></li> <li><a href="/solution/waimaowz.html" title="外贸网站建设解决方案">外贸网站建设解决方案</a></li> <li><a href="/solution/pingpaiwz.html" title="品牌形象网站建设解决方案">品牌形象网站建设解决方案</a></li> <li><a href="/solution/dianziwz.html" title="数码、电子产品网站建设解决方案">数码、电子产品网站建设解决方案</a></li> <li><a href="/solution/jituanwz.html" title="集团、上市企业网站建设解决方案">集团、上市企业网站建设解决方案</a></li> <li><a href="/solution/dichanwz.html" title="房地产、地产项目网站建设解决方案">房地产、地产项目网站建设解决方案</a></li> <li><a href="/solution/zhubaowz.html" title="珠宝高端奢侈品网站建设解决方案">珠宝高端奢侈品网站建设解决方案</a></li> </ul> </div> <div class="links w2"> <h2 class="h2">我们的实力<a href="/about/" title="更多" class="more">更多+</a></h2> <ul> <li>10年专业互联网服务经验</li> <li>成都高端建站设计团队</li> <li>资深行业分析策划</li> <li>B2C营销型网站建设者</li> <li>前沿视觉设计、研发能力</li> <li>前端代码深度符合SEO优化</li> <li>成都市高新技术企业证书</li> <li>具有完备的项目管理</li> <li>完善的售后服务体系</li> <li>深厚的网络运营经验</li> <li>时刻新技术研发能力</li> <li>16个网站系统软件著作权</li> </ul> </div> <div class="f_div2_r"> <h2 class="h2">关于甜橘子<a href="/about/" title="更多" class="more">更多+</a></h2> 甜橘子网站设计,为客户量身定制各类网站建设业务,包括企业型、电子商务型、行业门户型、品牌建立型等各类网站,实战经验丰富,成功案例众多。以客户利益为出发点,甜橘子网站制作为客户规划、定制符合企业需求、带有营销价值的建站方案,提供从网站前期定位分析策划到网站界面设计... </div> <div class="c_l"></div> </div> <div class="wrap"> <div class="f_div3"> <span class="l">成都网站制作案例©2020 甜橘子设计 版权所有 | <a href="http://chengdu.cdxwcx.cn" target="_blank">甜橘子网站设计</a><a href="http://chengdu.cdxwcx.cn" target="_blank">chengdu.cdxwcx.cn</a></span> <span class="r"><a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">蜀ICP备11025516号</a></span> </div> </div> </div> </footer> <!--尾部end--> <script language="javascript" src="/Public/Home/js/foot.js"></script> <!--尾部end--> <!--侧边栏begin--> <div class="side"> <ul> <li id="qqonline_xbceo"><a href="tencent://message/?uin=631063699&Site=&Menu=yes"><i class="bgs1"></i>QQ咨询</a></li> <li class="shangqiao"><a href="tencent://message/?uin=532337155&Site=&Menu=yes" title="在线咨询"> <div><i class="bgs2"></i>在线咨询</div> </a></li> <li class="sideewm"><i class="bgs3"></i>官方微信 <div class="ewBox"></div> </li> <li class="sideetel"><i class="bgs4"></i>联系电话 <div class="telBox"> <dd class="bgs1"><span>座机</span><a href="tel:028-86922220" target="_blank">028-86922220</a></dd> <dd class="bgs2"><span>手机</span><a href="tel:13518219792" target="_blank">13518219792</a></dd> </div> </li> <li class="sidetop" onClick="goTop()" id="sidetop"><i class="bgs6"></i>返回顶部</li> </ul> </div> <script type="text/javascript"> $('.sideewm').hover(function(){ $('.ewBox').stop().fadeIn(); },function(){ $('.ewBox').stop().fadeOut(); }); $('.sideetel').hover(function(){ $('.telBox').stop().fadeIn(); },function(){ $('.telBox').stop().fadeOut(); }); $(".con_id 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); } }); </script> <!-- WPA start --> <!-- WPA end --> <!--侧边栏end--> </body> </html>