免费不卡亚洲欧美,一本色道久久综合亚洲精品不卡,久草在线免费福利http://www.aygfsteel.com/tyjava/category/51207.html在學習中進步,在進步中學習!zh-cnMon, 26 Mar 2012 08:24:51 GMTMon, 26 Mar 2012 08:24:51 GMT60$.getJSON(url,null,function call(data){});http://www.aygfsteel.com/tyjava/articles/372689.htmlcanry Tongcanry TongMon, 26 Mar 2012 02:47:00 GMThttp://www.aygfsteel.com/tyjava/articles/372689.htmlhttp://www.aygfsteel.com/tyjava/comments/372689.htmlhttp://www.aygfsteel.com/tyjava/articles/372689.html#Feedback0http://www.aygfsteel.com/tyjava/comments/commentRss/372689.htmlhttp://www.aygfsteel.com/tyjava/services/trackbacks/372689.html
  前臺js代碼:
<script type="text/javascript">
//<![CDATA[ 
function convertUrl(url){
    var timestamp 
= (new Date()).valueOf();
    
if(url.indexOf("?")>=0){
        url 
= url+"&t="+timestamp;
    }
else{
        url 
= url+"?t="+timestamp;
    }
    
return url;
}

$(function(){
    var newUrl01 
= "/html/school/schoolTJSchoolWeb.do?sch_hot=3";
    $.getJSON(convertUrl(newUrl01),
null,function call(data){  
        var myTitle
="";
        
for(var i=0; i<$(data).length-1 ;i++){
            var otherObj 
= $(data).get(i+1);
            
if(otherObj.sch_name.length>21){
            myTitle 
+="<li id='sch_name'><a href='/html/school/viewInfoSchoolWeb.do?sch_id="+otherObj.sch_id+"'>"+otherObj.sch_name.substring(0,21)+'..'+"</a></li>";
            }
else{
            myTitle 
+="<li id='sch_name'><a href='/html/school/viewInfoSchoolWeb.do?sch_id="+otherObj.sch_id+"'>"+otherObj.sch_name+"</a></li>";
            }
        }
        $(
"#school_ul01").html(myTitle);
    }); 
    
    var newUrl 
= "/html/school/adSchoolWeb.do";
    $.getJSON(convertUrl(newUrl),
null,function call(data){  
        var myTitle
="";
        
for(var i=0; i<$(data).length ;i++){
            var otherObj 
= $(data).get(i);
            myTitle 
+="<li><a href='#'><img width='220' height='70' src='/"+otherObj.AD_FILE_PATH+"' alt='廣告' /></a></li>";
        }
        $(
"#ad_ul").html(myTitle);
    }); 
});
         
//]]>
</script>

  前臺jsp代碼:

<html>
<head>
<title></title>
</head>
<body>
<div>
  
<ul id="school_ul01">
    
<li></li>
  
</ul>
  
<ul id="ad_ul">
    
<li></li>
  
</ul>
</div>
</body>
</html>

  后臺java代碼:

    
public void  schoolTJ() throws Exception{
        HttpServletResponse response 
= ServletActionContext.getResponse();
        HttpServletRequest request 
= ServletActionContext.getRequest();
        String sch_hot 
= request.getParameter("sch_hot");
        List
<DragonSchool> schoolList = (List<DragonSchool>this.webDragonSchoolService.list("select * from dragon_school where SCH_HOT ='"+sch_hot+"' limit 0,10", DragonSchool.class); 
        Gson gson 
= new Gson();
        String schoolListToJson 
= gson.toJson(schoolList);
        response.setCharacterEncoding(
"utf-8");
        response.getWriter().write(schoolListToJson);
        response.getWriter().close();
    }
    
    
public void ad() throws Exception{
        HttpServletResponse response 
= ServletActionContext.getResponse();
        List adList 
= webDragonAdvertisingService.webList(pager, "4"null9);
        Gson gson 
= new Gson();
        String adListToJson 
= gson.toJson(adList);
        response.setCharacterEncoding(
"utf-8");
        response.getWriter().write(adListToJson);
        response.getWriter().close();
    }


canry Tong 2012-03-26 10:47 發表評論
]]>
$.get(url,function call(data){});http://www.aygfsteel.com/tyjava/articles/372541.htmlcanry Tongcanry TongFri, 23 Mar 2012 06:13:00 GMThttp://www.aygfsteel.com/tyjava/articles/372541.htmlhttp://www.aygfsteel.com/tyjava/comments/372541.htmlhttp://www.aygfsteel.com/tyjava/articles/372541.html#Feedback0http://www.aygfsteel.com/tyjava/comments/commentRss/372541.htmlhttp://www.aygfsteel.com/tyjava/services/trackbacks/372541.html    今天做項目遇到這樣的需求,每個頁面header部分和body部分之間要有3張圖片,中間部分的圖片是靜態的,而左右兩側需要從數據庫動態查出,即廣告位;
開始的思路:
    如果單純的是一個頁面還好說,思路是在請求Action時,在相應方法中加入數據庫查詢方法,響應后接到list顯示圖片即可;
難題的出現:   
    但現在的情況是,有多個jsp頁面需要接收這個list,也就是說,按原來的思路,首先需要將該部分做成公共jsp頁面,使用<%@ include file="/include/advertising.jsp" %>進行包含使用,其次在所有涉及該廣告顯示的jsp頁面鏈接請求的Action中加入數據庫查詢方法;
    想想這個工作量有多大,而且在團隊合作開發的今天,我在別人完成的代碼的基礎上加入某些代碼,稍不留意就會有遺漏,導致項目出現問題!
最終的解決方案(最好的)
    怎么辦呢?Ajax!!神奇的Ajax!!對我來說Ajax顯得很陌生,即便做了半年多的web開發,即便Ajax在web開發中應用很廣泛,到了今天我才真正認識到Ajax的力量!貼代碼吧,見證“我的Ajax”:

公共頁面advertising.jsp代碼:

<%@ page contentType="text/html; charset=utf-8" language="java" errorPage="" %>
<script type="text/javascript">
//<![CDATA[
$(function(){
        var url1 
= "/getAdAdvertisingAction.do";
        $.get(url1,function call(data){
                var array 
= data.split(",");
                document.getElementById(
"left_ad01").src = array[0];
                document.getElementById(
"left_ad02").src = array[1];
        });
    });
//]]>
</script>

<ul id="banner">
    
<li class="ml_0"><img id="left_ad01" width="173" height="90" src="/images/banner/img01_banner.png" alt="廣告" /></li>
    
<li><img src="/images/banner/img02_banner.png" alt="廣告" /></li>
    
<li><img id="left_ad02" width="173" height="90" src="/images/banner/img03_banner.png" alt="廣告"  /></li>
    
</ul>

引用頁main.jsp代碼(多個頁面引用,這里以main.jsp為例):

<%@ page contentType="text/html; charset=utf-8" language="java" errorPage="" %>
<html>
<title></title>
<head></head>
<body>
<%@ include file="/include/header.jsp" %>
<%@ include file="/include/advertising.jsp" %>
<div></div>
<%@ include file="/include/footer.jsp" %>
</boday>
</html>

后臺Action.java代碼:

public void getAd() throws Exception {
        HttpServletResponse response 
= ServletActionContext.getResponse();
        List
<DragonAdvertising> adList = dragonAdvertisingService.webList(pager, "1""1"1);
        List
<DragonAdvertising> adList1 = dragonAdvertisingService.webList(pager, "1""2"1);
        response.getWriter().write(
"/"+adList.get(0).getAD_FILE_PATH()+","+"/"+adList1.get(0).getAD_FILE_PATH());
        response.getWriter().close();
    }

  就是這樣,所有想似復雜和看似復雜的問題就這樣解決了;
  當然,Ajax的應用遠沒有這樣簡單,還有很多復雜的方法和原理我還沒有見過,慢慢學習吧!


canry Tong 2012-03-23 14:13 發表評論
]]>
主站蜘蛛池模板: 高陵县| 金坛市| 贵溪市| 原平市| 毕节市| 青海省| 乐平市| 开化县| 鸡西市| 黄平县| 灌云县| 祁阳县| 琼结县| 额尔古纳市| 台中市| 山东省| 陆良县| 剑川县| 海兴县| 永嘉县| 新昌县| 晴隆县| 绥阳县| 汕头市| 乐平市| 额尔古纳市| 应用必备| 铁力市| 兴城市| 彩票| 巴彦淖尔市| 固始县| 浦东新区| 铁力市| 夏邑县| 和田市| 沂水县| 岐山县| 庐江县| 松潘县| 左贡县|