JSP中Application如何使用-成都创新互联网站建设

关于创新互联

多方位宣传企业产品与服务 突出企业形象

公司简介 公司的服务 荣誉资质 新闻动态 联系我们

JSP中Application如何使用

这篇文章将为大家详细讲解有关JSP中Application如何使用,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

创新互联建站是一家以网站建设公司、网页设计、品牌设计、软件运维、营销推广、小程序App开发等移动开发为一体互联网公司。已累计为成都轻质隔墙板等众行业中小客户提供优质的互联网建站和软件开发服务。

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访问量很高,那么就应该在这方面多花点时间优化。

数据库连接缓冲

      <%    cods.setURL("jdbc:oracle:thin:@HOST:PORT:SID");   cods.setUser("scott");   cods.setPassword("tiger");   cods.setStmtCache (5);    %>   event:application_OnStart>   <%@ page import="java.sql.*, javax.sql.*, oracle.jdbc.pool.*" %>  * This is a JavaServer Page that uses Connection Caching over   application   * scope. The Cache is created in an application scope in   globals.jsa file.    * Connection is obtained from the Cache and recycled back once   done.              ConnCache JSP   TITLE>   HEAD>   <BODY BGCOLOR=EOFFFO>    <H1> Hello    <%= (request.getRemoteUser() != null? ", " +   request.getRemoteUser() : "") %>   ! I am Connection Caching JSP.   H1>   <HR>   <B> I get the Connection from the Cache and recycle it back.   B>    <P>   <%   try {   Connection conn = cods.getConnection();   Statement stmt = conn.createStatement ();   ResultSet rset = stmt.executeQuery ("SELECT ename, sal " +    "FROM scott.emp ORDER BY ename");   if (rset.next()) {   %>   <TABLE BORDER=1 BGCOLOR="C0C0C0">   <TH WIDTH=200 BGCOLOR="white"> <I>Employee NameI> TH>   <TH WIDTH=100 BGCOLOR="white"> <I>SalaryI> TH>   <TR> <TD ALIGN=CENTER> <%= rset.getString(1) %> TD>   <TD ALIGN=CENTER> $<%= rset.getDouble(2) %> TD>   TR>   <% while (rset.next()) {   %>   <TR> <TD ALIGN=CENTER> <%= rset.getString(1) %> TD>   <TD ALIGN=CENTER> $<%= rset.getDouble(2) %> TD>   TR>   <% }   %>   TABLE>   <% }    else {   %>   <P> Sorry, the query returned no rows! P>   <%    }   rset.close();   stmt.close();   conn.close(); // Put the Connection Back into the Pool   } catch (SQLException e) {   out.println("<P>" + "There was an error doing the query:");   out.println ("<PRE>" + e + "PRE> n <P>");   }   %>   BODY>   HTML></pre><p>关于JSP中Application如何使用就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。</p>            
            
                        <br>
            标题名称:JSP中Application如何使用            <br>
            URL分享:<a href="http://kswsj.cn/article/gidpjg.html">http://kswsj.cn/article/gidpjg.html</a>
        </div>
    </div>
    <div class="other">
        <h3>其他资讯</h3>
        <ul>
            <li>
                    <a href="/article/hecchc.html">go语言快速学习方法,自学go语言</a>
                </li><li>
                    <a href="/article/heccjd.html">mysql字符集怎么查,如何查看字符集mysql</a>
                </li><li>
                    <a href="/article/hecchd.html">python闭包内函数,python中闭包必须存在于什么关系的函数中</a>
                </li><li>
                    <a href="/article/heccgp.html">vb.net查找文本,vb 字符串查找</a>
                </li><li>
                    <a href="/article/heccpo.html">java代码保存,java写好的代码怎么保存</a>
                </li>        </ul>
    </div>
</div>
<div class="line"></div>
<!--底部-->
<footer id="5">
    <div class="foot1 container">
        <div class="list">
            <div class="item">
                <a href="javascript:;">
                    <span class="ico1"><i class="iconfont"></i><img src="/Public/Home/img/ewm.png" alt=""></span>
                    <strong>关注我们</strong>
                </a>
            </div>
            <div class="item">
                <a href="" target="_blank">
                    <span><i class="iconfont"></i></span>
                    <strong>索要报价</strong>
                </a>
            </div>
            <div class="item">
                <a href="" target="_blank">
                    <span><i class="iconfont"></i></span>
                    <strong>我要咨询</strong>
                </a>
            </div>
            <div class="item">
                <a href="" target="_blank">
                    <span><i class="iconfont"></i></span>
                    <strong>找到我们</strong>
                </a>
            </div>
            <div class="item">
                <a href="" target="_blank">
                    <span><i class="iconfont"></i></span>
                    <strong>投诉建议</strong>
                </a>
            </div>
        </div>
        <div class="tel">
            <dl>
                <tel><a href="tel:400-028-6601" target="_blank">400-028-6601</a></tel><br>
                <span>也许您需要专业的服务,欢迎来电咨询</span>
            </dl>
            <dl>
                <tel><a href="tel:18980820575" target="_blank">18980820575</a></tel><br>
                <span>您的需求,是我们前进的动力</span>
            </dl>
        </div>
    </div>
    <div class="friend">
        <div class="container">
            <span class="tit">友情链接:</span>
            <div class="inner">
                <a href="https://www.cdcxhl.com/quanwang.html" target="_blank">全网整合营销推广</a><a href="https://www.cdcxhl.com/ruanwen/" target="_blank">软文营销</a><a href="https://www.cdcxhl.com/" target="_blank">成都网站建设</a><a href="https://www.cdcxhl.com/" target="_blank">成都网站制作</a><a href="https://www.cdcxhl.com/" target="_blank">成都网站制作公司</a><a href="https://www.cdcxhl.com/tuoguan/" target="_blank">IDC机房托管</a><a href="https://www.cdcxhl.com/waimao.html" target="_blank">外贸建站</a><a href="https://www.cdcxhl.com/ruanwen/" target="_blank">营销软文</a><a href="https://www.cdcxhl.com/wangzhandingzhi.html" target="_blank">成都企业网站定制</a><a href="https://www.cdcxhl.com/" target="_blank">网站设计</a><a href="https://www.cdcxhl.com/xiangyingshi.html" target="_blank">响应式网站建设</a><a href="https://www.cdcxhl.com/google.html" target="_blank">谷歌推广</a><a href="https://www.cdcxhl.com/waimao.html" target="_blank">外贸营销网站</a><a href="https://www.cdcxhl.com/zuyong/" target="_blank">服务器租用</a><a href="https://www.cdcxhl.com/ruanwen/" target="_blank">发布软文</a><a href="https://www.cdcxhl.com/xiangyingshi.html" target="_blank">成都响应式网站建设公司</a><a href="https://www.cdxwcx.com/jifang/xiyun.html" target="_blank">西云移动机房</a><a href="https://www.cdcxhl.com/jigui/" target="_blank">服务器机柜租用</a>            </div>
        </div>
    </div>
    <div class="foot">
        <div class="container">
            <div class="footNav">
                <h3>网站建设</h3>
                <a href="http://m.cdcxhl.cn/H5/" target="_blank">成都响应式网站建设</a><a href="http://www.cdkjz.cn/fangan/" target="_blank">网站建设方案</a><a href="https://www.cdxwcx.com/city/shuangliu/" target="_blank">双流网站建设</a>            </div>
            <div class="footNav">
                <h3>服务器托管</h3>
                <a href="https://www.cdcxhl.com/idc/guanghua.html" target="_blank">光华服务器托管</a><a href="https://www.cdcxhl.com/tuoguan.html" target="_blank">成都服务器托管</a><a href="http://www.cqfuwuqi.com/" target="_blank">重庆服务器托管</a>            </div>
            <div class="footNav">
                <h3>网站制作</h3>
                <a href="https://www.cdcxhl.com/zhizuo/chengdu.html" target="_blank">四川成都网站制作</a><a href="http://www.cdxwcx.cn/bj/" target="_blank">网站制作报价</a><a href="http://www.cdxtjz.com/" target="_blank">网站制作</a>            </div>
            <div class="footNav">
                <h3>企业服务</h3>
                <a href="https://www.cdcxhl.com/ruanwen/yingxiao/" target="_blank">软文推广</a><a href="https://www.cdcxhl.com/ruanwen/yingxiao/" target="_blank">软文营销</a><a href="https://www.cdcxhl.com/service/ypfwzgz.html" target="_blank">互联网药品信息服务资格证</a>            </div>
            <div class="fr ecode">
                <div class="fl">
                    <img src="/Public/Home/img/ewm.jpg">
                    <p>关注企业微信</p>
                </div>
                <div class="fr slogan">
                    <p class="icon">
                        <a class="ph" href=""><i class="iconfont"></i></a>
                        <a class="qq" href="tencent://message/?uin=1683211881&Site=&Menu=yes"><i class="iconfont"></i></a>
                    </p>
                    <p>
                        <i>想要找 </i> <a href="">小程序开发</a>、<a href="">APP开发</a>、
                        <a href="">营销型网站建设</a>、<a href="">网站建设</a>、
                        <i><a href="">网站定制开发</a></i> ,就选<a href="">创新互联</a>
                    </p>
                </div>
            </div>
        </div>
        <div class="bottom container">
            <p class="fl">
                版权所有:成都创新互联科技有限公司
                备案号:<a href="https://beian.miit.gov.cn/" target="_blank" rel="nofollow">蜀ICP备19037934号</a>
                服务热线:028-86922220
            </p>
            <p class="fr">
                <a href="https://www.cdxwcx.com/" target="_blank">成都网站建设</a>:
                <a href="https://www.cdcxhl.com/" target="_blank">创新互联</a>
            </p>
        </div>
    </div>
</footer>
<!--在线咨询-->
<div class="fot">
    <ul>
        <li>
            <a href="https://p.qiao.baidu.com/cps/mobileChat?siteId=11284691&userId=6256368&type=1&reqParam=%20{%22from%22:0,%22sessionid%22:%22%22,%22siteId%22:%2211284691%22,%22tid%22:%22-1%22,%22userId%22:%226256368%22,%22ttype%22:1,%22siteConfig%22:%20{%22eid%22:%226256368%22,%22queuing%22:%22%22,%22siteToken%22:%226ce441ff9e2d6bedbdfc2a4138de449e%22,%22userId%22:%226256368%22,%22isGray%22:%22false%22,%22wsUrl%22:%22wss://p.qiao.baidu.com/cps3/websocket%22,%22likeVersion%22:%22generic%22,%22siteId%22:%2211284691%22,%22online%22:%22true%22,%22webRoot%22:%22//p.qiao.baidu.com/cps3/%22,%22bid%22:%22160142915792139572%22,%22isSmallFlow%22:0,%22isPreonline%22:0,%22invited%22:0%20},%22config%22:%20{%22themeColor%22:%224d74fa%22%20}%20}&appId=&referer=&iswechat=0&expectWaiter=-1&openid=null&otherParam=null&telephone=null&speedLogId=null&eid=null&siteToken=6ce441ff9e2d6bedbdfc2a4138de449e" target="_blank">
                <img src="/Public/Home/img/fot1.png" alt="">
                <p>在线咨询</p>
            </a>
        </li>
        <li>
            <a href="tel:18980820575" target="_blank">
                <img src="/Public/Home/img/fot2.png" alt="">
                <p>拨打电话</p>
            </a>
        </li>
    </ul>
</div>
</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>