国产精品久久久亚洲,亚洲成AV人片在线观看无码,亚洲成电影在线观看青青http://m.tkk7.com/xzclog/category/17326.htmlzh-cnTue, 24 Jul 2012 21:03:51 GMTTue, 24 Jul 2012 21:03:51 GMT60avaScript世界的一等公民 - 函數(shù)http://m.tkk7.com/xzclog/archive/2012/07/24/383831.htmlxzcxzcTue, 24 Jul 2012 05:45:00 GMThttp://m.tkk7.com/xzclog/archive/2012/07/24/383831.htmlhttp://m.tkk7.com/xzclog/comments/383831.htmlhttp://m.tkk7.com/xzclog/archive/2012/07/24/383831.html#Feedback0http://m.tkk7.com/xzclog/comments/commentRss/383831.htmlhttp://m.tkk7.com/xzclog/services/trackbacks/383831.html閱讀全文

xzc 2012-07-24 13:45 發(fā)表評(píng)論
]]>
靜態(tài)html文件js讀取url參數(shù) http://m.tkk7.com/xzclog/archive/2011/12/12/366165.htmlxzcxzcMon, 12 Dec 2011 09:15:00 GMThttp://m.tkk7.com/xzclog/archive/2011/12/12/366165.htmlhttp://m.tkk7.com/xzclog/comments/366165.htmlhttp://m.tkk7.com/xzclog/archive/2011/12/12/366165.html#Feedback0http://m.tkk7.com/xzclog/comments/commentRss/366165.htmlhttp://m.tkk7.com/xzclog/services/trackbacks/366165.html在ajax應(yīng)用流行時(shí),有時(shí)我們可能為了降低服務(wù)器的負(fù)擔(dān),把動(dòng)態(tài)內(nèi)容生成靜態(tài)html頁(yè)面或者是xml文件,供客戶端訪問(wèn)!但是在我們的網(wǎng)站或系統(tǒng)中往住頁(yè)面中某些部分是在后臺(tái)沒(méi)有進(jìn)行修改時(shí),其內(nèi)容不會(huì)發(fā)生變化的。但是頁(yè)面中也往往有部分內(nèi)容是動(dòng)態(tài)的更新的,比如一個(gè)新聞頁(yè)面,新聞內(nèi)容往往生成了之后就是靜態(tài)的,但是新聞的最新評(píng)論往往是變化的,在這個(gè)時(shí)候有幾種解決方案:

1、重新生成該靜態(tài)頁(yè)面,優(yōu)點(diǎn)是用戶訪問(wèn)時(shí)頁(yè)面上的肉容可以實(shí)現(xiàn)全靜態(tài),不與服務(wù)器程序及數(shù)據(jù)庫(kù)后端打交道!缺點(diǎn)是每次用戶對(duì)頁(yè)面任何部分更新都必須重新生成。

2、js調(diào)用請(qǐng)求動(dòng)態(tài)內(nèi)容,優(yōu)點(diǎn)是靜態(tài)頁(yè)面只生成一次,動(dòng)態(tài)部分才動(dòng)態(tài)加載,卻點(diǎn)是服務(wù)器端要用輸出一段js代碼并用js代碼輸出網(wǎng)頁(yè)內(nèi)容,也不利于搜索引擎收錄。

3、ajax調(diào)用動(dòng)態(tài)內(nèi)容,和js基本相似,只是與服務(wù)器交互的方式不同!并且頁(yè)面顯示不會(huì)受到因動(dòng)態(tài)調(diào)用速度慢而影響整個(gè)頁(yè)面的加載速度!至于ajax不利于搜索收錄,當(dāng)然在《ajax in acation》等相關(guān)書(shū)籍中也介紹有變向的解決方案!

4、在服務(wù)器端ssl動(dòng)態(tài)內(nèi)容,用服務(wù)器端優(yōu)化及緩存解決是時(shí)下最流行的方法!

對(duì)于第二種和第三種方法都是我最青睞的靜態(tài)解決方法,適合以內(nèi)容為主的中小型網(wǎng)站。那么在有時(shí)候可能會(huì)有js讀取url參數(shù)的需求,事實(shí)證明的確也有很多時(shí)候有這種需求,特別是在胖客戶端的情況下!以前也寫(xiě)過(guò)這樣的代碼,其實(shí)原理很簡(jiǎn)單就是利用javascript接口提供location對(duì)像得到url地址,然后通過(guò)分析url以取得參數(shù),以下是我收錄的一些優(yōu)秀的url參數(shù)讀取代碼:

一、字符串分割分析法。
這里是一個(gè)獲取URL+?帶QUESTRING參數(shù)的JAVASCRIPT客戶端解決方案,相當(dāng)于asp的request.querystring,PHP的$_GET
函數(shù):

<script>
function GetRequest()
{
var url = location.search; //獲取url中"?"符后的字串
var theRequest = new Object();
if(url.indexOf("?") != -1)
{
  var str = url.substr(1);
    strs = str.split("&");
  for(var i = 0; i < strs.length; i ++)
    {
     theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
    }
}
return theRequest;
}
</script>

然后我們通過(guò)調(diào)用此函數(shù)獲取對(duì)應(yīng)參數(shù)值:

<script>
var Request=new Object();
Request=GetRequest();
var 參數(shù)1,參數(shù)2,參數(shù)3,參數(shù)N;
參數(shù)1=Request['參數(shù)1'];
參數(shù)2=Request['參數(shù)2'];
參數(shù)3=Request['參數(shù)3'];
參數(shù)N=Request['參數(shù)N'];
</script>


以此獲取url串中所帶的同名參數(shù)

二、正則分析法。

function     GetQueryString(name)   
{   
     var     reg     =   new   RegExp("(^|&)"+     name     +"=([^&]*)(&|$)");   
     var     r     =     window.location.search.substr(1).match(reg);   
     if     (r!=null)   return     unescape(r[2]);   return   null;   
}   
alert(GetQueryString("參數(shù)名1"));   
alert(GetQueryString("參數(shù)名2"));   
alert(GetQueryString("參數(shù)名3"));

xzc 2011-12-12 17:15 發(fā)表評(píng)論
]]>
Java Cookie 中文亂碼解決方法 http://m.tkk7.com/xzclog/archive/2011/10/03/359956.htmlxzcxzcMon, 03 Oct 2011 03:29:00 GMThttp://m.tkk7.com/xzclog/archive/2011/10/03/359956.htmlhttp://m.tkk7.com/xzclog/comments/359956.htmlhttp://m.tkk7.com/xzclog/archive/2011/10/03/359956.html#Feedback0http://m.tkk7.com/xzclog/comments/commentRss/359956.htmlhttp://m.tkk7.com/xzclog/services/trackbacks/359956.html
  • import java.net.*;    
  • String   key=URLEncoder.encode("中文key","GBK");   
  • String   value=URLEncoder.encode("中文value","GBK");   
  • Cookie   cook=new Cookie(key,value);        
  • String   key=cook.getName(),value=cook.getValue();      
  • key=URLDecoder.decode(key,"GBK");      
  • value=URLDecoder.decode(value,"GBK");   


  •  

    String value = java.net.URLEncoder.encode("中文","utf-8");

    Cookie cookie = new Cookie("chinese_code",value);

    cookie.setMaxAge(60*60*24*6);

    response.addCookie(cookie);

     

     

     

    encode() 只有一個(gè)參數(shù)的已經(jīng)過(guò)時(shí)了,現(xiàn)在可以設(shè)置編碼格式, 取cookie值的時(shí)候 也不用解碼了。

     



    xzc 2011-10-03 11:29 發(fā)表評(píng)論
    ]]>
    web.xml中l(wèi)oad-on-startup的作用http://m.tkk7.com/xzclog/archive/2011/09/29/359789.htmlxzcxzcThu, 29 Sep 2011 07:22:00 GMThttp://m.tkk7.com/xzclog/archive/2011/09/29/359789.htmlhttp://m.tkk7.com/xzclog/comments/359789.htmlhttp://m.tkk7.com/xzclog/archive/2011/09/29/359789.html#Feedback1http://m.tkk7.com/xzclog/comments/commentRss/359789.htmlhttp://m.tkk7.com/xzclog/services/trackbacks/359789.html如下一段配置,熟悉DWR的再熟悉不過(guò)了:
    <servlet>
       <servlet-name>dwr-invoker</servlet-name>
       <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
       <init-param>
        <param-name>debug</param-name>
        <param-value>true</param-value>
       </init-param>
       <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
       <servlet-name>dwr-invoker</servlet-name>
       <url-pattern>/dwr/*</url-pattern>
    </servlet-mapping>

    我們注意到它里面包含了這段配置:<load-on-startup>1</load-on-startup>,那么這個(gè)配置有什么作用呢?

    貼一段英文原汁原味的解釋如下:
    Servlet specification:
    The load-on-startup element indicates that this servlet should be loaded (instantiated and have its init() called) on the startup of the web application. The optional contents of these element must be an integer indicating the order in which the servlet should be loaded. If the value is a negative integer, or the element is not present, the container is free to load the servlet whenever it chooses.   If the value is a positive integer or 0, the container must load and initialize the servlet as the application is deployed. The container must guarantee that servlets marked with lower integers are loaded before servlets marked with higher integers. The container may choose the order of loading of servlets with the same load-on-start-up value.

    翻譯過(guò)來(lái)的意思大致如下:
    1)load-on-startup元素標(biāo)記容器是否在啟動(dòng)的時(shí)候就加載這個(gè)servlet(實(shí)例化并調(diào)用其init()方法)。

    2)它的值必須是一個(gè)整數(shù),表示servlet應(yīng)該被載入的順序

    2)當(dāng)值為0或者大于0時(shí),表示容器在應(yīng)用啟動(dòng)時(shí)就加載并初始化這個(gè)servlet;

    3)當(dāng)值小于0或者沒(méi)有指定時(shí),則表示容器在該servlet被選擇時(shí)才會(huì)去加載。

    4)正數(shù)的值越小,該servlet的優(yōu)先級(jí)越高,應(yīng)用啟動(dòng)時(shí)就越先加載。

    5)當(dāng)值相同時(shí),容器就會(huì)自己選擇順序來(lái)加載。

    所以,<load-on-startup>x</load-on-startup>,中x的取值1,2,3,4,5代表的是優(yōu)先級(jí),而非啟動(dòng)延遲時(shí)間。

    如下題目:

    2.web.xml中不包括哪些定義(多選)

    a.默認(rèn)起始頁(yè)

    b.servlet啟動(dòng)延遲時(shí)間定義

    c.error處理頁(yè)面

    d.jsp文件改動(dòng)后重新載入時(shí)間

    答案:b,d

    通常大多數(shù)Servlet是在用戶第一次請(qǐng)求的時(shí)候由應(yīng)用服務(wù)器創(chuàng)建并初始化,但<load-on-startup>n</load-on-startup>   可以用來(lái)改變這種狀況,根據(jù)自己需要改變加載的優(yōu)先級(jí)!



    xzc 2011-09-29 15:22 發(fā)表評(píng)論
    ]]>
    js 高級(jí)編程http://m.tkk7.com/xzclog/archive/2011/07/09/353978.htmlxzcxzcSat, 09 Jul 2011 03:34:00 GMThttp://m.tkk7.com/xzclog/archive/2011/07/09/353978.htmlhttp://m.tkk7.com/xzclog/comments/353978.htmlhttp://m.tkk7.com/xzclog/archive/2011/07/09/353978.html#Feedback2http://m.tkk7.com/xzclog/comments/commentRss/353978.htmlhttp://m.tkk7.com/xzclog/services/trackbacks/353978.html

    研究發(fā)現(xiàn):屬性(變量)可分為三類(對(duì)象屬性、全局變量和局部變量)
    對(duì)象屬性:聲明時(shí)以“this.”開(kāi)頭,只能被“類的實(shí)例”即對(duì)象所調(diào)用,不能被“類內(nèi)部(對(duì)外不對(duì)內(nèi))”調(diào)用;全局變量:聲明時(shí)直接以變量名開(kāi)頭,可以任意調(diào)用(對(duì)內(nèi)對(duì)外);局部變量:只能被

    “類內(nèi)部(對(duì)內(nèi)不對(duì)外)”調(diào)用。

     

    JS函數(shù)的聲明與訪問(wèn)原理

    <script type="text/javascript">  
    //類  
    var testClass = function(){  
      //對(duì)象屬性(對(duì)外不對(duì)內(nèi),類調(diào)用)  
      this.age ="25";  
      //全局變量(對(duì)內(nèi)對(duì)外)  
      name="jack";  
      //局部變量(對(duì)內(nèi)不對(duì)外)
      var address = "beijing";
        
      //全局函數(shù)(對(duì)內(nèi)對(duì)外)  
      add = function(a,b){  
        //可訪問(wèn):全局變量和局部變量  
        multiply(a,b);  
        return a+b;  
      }  
      //實(shí)例函數(shù)(由類的對(duì)象調(diào)用)  
      this.minus = function(a,b){  
        //可以訪問(wèn):對(duì)象屬性、全局變量和局部變量  
        return a-b;  
      }  
      //局部函數(shù)(內(nèi)部直接調(diào)用)  
      var multiply = function(a,b){  
        //只能訪問(wèn):全局變量和局部變量  
        return a*b;  
      }  
    }  
     
     
    //類函數(shù)(由類名直接調(diào)用)  
    testClass.talk= function(){  
      //只能訪問(wèn):全局變量和全局函數(shù)  
      this.what = function(){  
        alert("What can we talk about?");  
        about();  
      }  
        
      var about = function(){  
        alert("about name:"+name);
        alert("about add(1,1):"+add(1,1));
      }  
    }  
     
     
    //原型函數(shù)(由類的對(duì)象調(diào)用)  
    testClass.prototype.walk = function(){  
      //只能訪問(wèn):全局變量和全局函數(shù)  
      this.where = function(){  
        alert("Where can we go?");
        go();  
      }  
        
      var go = function(){  
        alert("go name:"+name); 
        alert("go add(1,1):"+add(1,1));
      }  
    }  
    </script> 


    下面看看如何調(diào)用:

    <script type="text/javascript">  
    //獲取一個(gè)cbs類的實(shí)例  
    var cbs= new testClass();  
    //調(diào)用類的對(duì)象屬性age  
    alert("age:"+cbs.age);  
     
    //獲取類函數(shù)talk的實(shí)例  
    var talk = new testClass.talk();
    //調(diào)用類函數(shù)的實(shí)例函數(shù)  
    talk.what();  
     
    //獲取原型函數(shù)walk的實(shí)例  
    var walk = new cbs.walk();  
    //調(diào)用原型函數(shù)的實(shí)例函數(shù)  
    walk.where();  
    </script> 



    xzc 2011-07-09 11:34 發(fā)表評(píng)論
    ]]>
    當(dāng)Ajax遭遇GBK編碼 (完全解決方案) http://m.tkk7.com/xzclog/archive/2011/06/21/352729.htmlxzcxzcTue, 21 Jun 2011 03:54:00 GMThttp://m.tkk7.com/xzclog/archive/2011/06/21/352729.htmlhttp://m.tkk7.com/xzclog/comments/352729.htmlhttp://m.tkk7.com/xzclog/archive/2011/06/21/352729.html#Feedback0http://m.tkk7.com/xzclog/comments/commentRss/352729.htmlhttp://m.tkk7.com/xzclog/services/trackbacks/352729.html 

    早起的國(guó)內(nèi)互聯(lián)網(wǎng)都使用GBK編碼,久之,所有項(xiàng)目都以GBK來(lái)編碼了。對(duì)于J2EE項(xiàng)目,為了減少編碼的干擾通常都是設(shè)置一個(gè)編碼的Filter,強(qiáng)制將Request/Response編碼改為GBK。例如一個(gè)Spring的常見(jiàn)配置如下:

     

    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>GBK</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    

    毫無(wú)疑問(wèn),這在GBK編碼的頁(yè)面訪問(wèn)、提交數(shù)據(jù)時(shí)是沒(méi)有亂碼問(wèn)題的。但是遇到Ajax就不一樣了。Ajax強(qiáng)制將中文內(nèi)容進(jìn)行UTF-8編碼,這樣導(dǎo)致進(jìn)入后端后使用GBK進(jìn)行解碼時(shí)發(fā)生亂碼。網(wǎng)上的所謂的終極解決方案都是扯淡或者過(guò)于復(fù)雜,例如下面的文章:

    這樣的文章很多,顯然:

    • 使用VB進(jìn)行UTF-8轉(zhuǎn)換成GBK提交是完全不可行(多瀏覽器、多平臺(tái)完全不可用)
    • 使用復(fù)雜的js函數(shù)進(jìn)行一次、多次編碼,后端進(jìn)行一次、多次解碼也是不靠譜的,成本太高,無(wú)法重復(fù)使用

    如果提交數(shù)據(jù)的時(shí)候能夠告訴后端傳輸?shù)木幋a信息是否就可以避免這種問(wèn)題?比如Ajax請(qǐng)求告訴后端是UTF-8,其它請(qǐng)求告訴后端是GBK,這樣后端分別根據(jù)指定的編碼進(jìn)行解碼是不是就解決問(wèn)題了。

    有兩個(gè)問(wèn)題:

    1. 如何通過(guò)Ajax告訴后端的編碼?Header過(guò)于復(fù)雜,Cookie成本太高,使用參數(shù)最方便。
    2. 后端何時(shí)進(jìn)行解碼?每一個(gè)請(qǐng)求進(jìn)行解碼,過(guò)于繁瑣;獲取參數(shù)時(shí)解碼,此時(shí)已經(jīng)亂碼;在Filter里面動(dòng)態(tài)設(shè)置編碼是最完善的方案。
    3. 如何從參數(shù)中獲取編碼?如果是POST的body顯然無(wú)法獲取,因此在獲取之前所有參數(shù)就已經(jīng)按照某種編碼解碼過(guò)了,無(wú)法還原。所以通過(guò)URL傳遞編碼最有效。支持GET/POST,同時(shí)成本很低。

    解決了上述問(wèn)題,來(lái)看具體實(shí)現(xiàn)方案。 列一段Java代碼:

    import java.io.IOException;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    
    import javax.servlet.FilterChain;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.springframework.util.ClassUtils;
    import org.springframework.web.filter.OncePerRequestFilter;
    
    /** 自定義編碼過(guò)濾器
     * @author imxylz (imxylz#gmail.com)
     * @sine 2011-6-9
     */
    public class MutilCharacterEncodingFilter extends OncePerRequestFilter {
    
        static final Pattern inputPattern = Pattern.compile(".*_input_encode=([\\w-]+).*");
    
        static final Pattern outputPattern = Pattern.compile(".*_output_encode=([\\w-]+).*");
    
        // Determine whether the Servlet 2.4 HttpServletResponse.setCharacterEncoding(String)
        // method is available, for use in the "doFilterInternal" implementation.
        private final static boolean responseSetCharacterEncodingAvailable = ClassUtils.hasMethod(HttpServletResponse.class,
              "setCharacterEncoding", new Class[] { String.class });
    
        private String encoding;
    
        private boolean forceEncoding = false;
    
        @Override
        protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
     throws ServletException, IOException {
            String url = request.getQueryString();
            Matcher m = null;
            if (url != null && (m = inputPattern.matcher(url)).matches()) {//輸入編碼
                String inputEncoding = m.group(1);
                request.setCharacterEncoding(inputEncoding);
                m = outputPattern.matcher(url);
                if (m.matches()) {//輸出編碼
                    response.setCharacterEncoding(m.group(1));
                } else {
                    if (this.forceEncoding && responseSetCharacterEncodingAvailable) {
                        response.setCharacterEncoding(this.encoding);
                    }
                }
            } else {
                if (this.encoding != null && (this.forceEncoding || request.getCharacterEncoding() == null)) {
                    request.setCharacterEncoding(this.encoding);
                    if (this.forceEncoding && responseSetCharacterEncodingAvailable) {
                        response.setCharacterEncoding(this.encoding);
                    }
                }
            }
            filterChain.doFilter(request, response);
        }
    
        public void setEncoding(String encoding) {
            this.encoding = encoding;
        }
    
        public void setForceEncoding(boolean forceEncoding) {
            this.forceEncoding = forceEncoding;
        }
    }
    
    

    解釋下:

    • 如果URL的QueryString中包含_input_encode就使用此編碼進(jìn)行設(shè)置Request編碼,以后參數(shù)按照此編碼進(jìn)行解析,例如如果是Ajax就傳入U(xiǎn)TF-8,如果是普通的GBK請(qǐng)求則無(wú)視此參數(shù)。
    • 如果無(wú)視此參數(shù),則按照web.xml中配置的編碼規(guī)則進(jìn)行反編碼,如果是GBK就按照GBK規(guī)則解析。
    • 對(duì)于輸出編碼同樣使用上述規(guī)則。需要輸出編碼依賴輸入編碼,也就是說(shuō)如果有一個(gè)_output_encode的輸出編碼,則同時(shí)需要有一個(gè)_input_encode編碼來(lái)指定輸入編碼。當(dāng)然你可以改造成不依賴輸入編碼。
    • 完全兼容Spring的org.springframework.web.filter.CharacterEncodingFilter編碼規(guī)則,只需要替換類即可。
    • 沒(méi)有繼承org.springframework.web.filter.CharacterEncodingFilter類的原因是,org.springframework.web.filter.CharacterEncodingFilter里面的encoding參數(shù)和forceEncoding參數(shù)是private,子類無(wú)法使用。在有_input_encode而無(wú)_output_encode的時(shí)候想依然保持Spring的Response解析規(guī)則的話無(wú)法做到,所以將里面的代碼拷貝過(guò)來(lái)使用。(為了展示方便,注釋都刪掉了)
    • 正則表達(dá)式可以改進(jìn)成只需要匹配一次,從而可以提高一點(diǎn)點(diǎn)效率。
    • 所有后端請(qǐng)求將無(wú)視編碼的存在,前端Ajax的GET/POST請(qǐng)求也將無(wú)視編碼的存在,只是在URL地址中加上一個(gè)_input_encode=UTF-8的參數(shù)。僅此而已。
    • 如果想輸出的編碼也是UTF-8,比如手機(jī)端請(qǐng)求、跨站請(qǐng)求等,則需要URL地址參數(shù)_input_encode=UTF-8&_output_encode=UTF-8。
    • 對(duì)于POST請(qǐng)求,編碼參數(shù)不能寫(xiě)在body里面,否則無(wú)法解析。
    • 顯然,這種終極解決方案,在任何編碼中都可以解決,GBK/UTF-8/ISO8859-1等編碼任何組合都可以實(shí)現(xiàn)。
    • 唯一局限性是,此解決方案限制在J2EE項(xiàng)目中,其它平臺(tái)不知是否有類似Filter這樣的組件能夠設(shè)置編碼的概念。



    xzc 2011-06-21 11:54 發(fā)表評(píng)論
    ]]>
    Buffalo Ajax框架使用 http://m.tkk7.com/xzclog/archive/2011/06/16/352439.htmlxzcxzcThu, 16 Jun 2011 08:44:00 GMThttp://m.tkk7.com/xzclog/archive/2011/06/16/352439.htmlhttp://m.tkk7.com/xzclog/comments/352439.htmlhttp://m.tkk7.com/xzclog/archive/2011/06/16/352439.html#Feedback0http://m.tkk7.com/xzclog/comments/commentRss/352439.htmlhttp://m.tkk7.com/xzclog/services/trackbacks/352439.html下載地址:http://sourceforge.net/project/showfiles.php?group_id=178867

    1.buffalo-2.0.jar
    在buffalo-2.0-bin里,把它加到Web應(yīng)用程序里的lib

    2.buffalo.js和prototype.js
    我把這兩個(gè)文件放到Web應(yīng)用程序的scripts/目錄下,buffalo.js在buffalo-2.0-bin里,prototype.js在buffalo-demo.war里找

    4.web.xml內(nèi)容
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" 
        xmlns
    ="http://java.sun.com/xml/ns/j2ee" 
        xmlns:xsi
    ="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation
    ="http://java.sun.com/xml/ns/j2ee 
        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    >
        
        
        
    <servlet>
            
    <servlet-name>bfapp</servlet-name>
            
    <servlet-class>net.buffalo.web.servlet.ApplicationServlet</servlet-class>
        
    </servlet>
        
    <servlet-mapping>
            
    <servlet-name>bfapp</servlet-name>
            
    <url-pattern>/bfapp/*</url-pattern>
        
    </servlet-mapping>
        
    </web-app>


    5.index.jsp文件
    <%@ page language="java" pageEncoding="UTF-8"%>


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      
    <head>
        
    <title>第一個(gè) buffalo 示例程序</title>
        
    <script language="JavaScript" src="scripts/prototype.js"></script>
        
    <script language="JavaScript" src="scripts/buffalo.js"></script>
        
    <script type="text/javascript">
        
    var endPoint="<%=request.getContextPath()%>/bfapp";
        
        
    var buffalo = new Buffalo(endPoint);
        
    function hello(me) {
            buffalo.remoteCall(
    "demoService.getHello", [me.value], function(reply) {
                alert(reply.getResult());
            })
        }
        
    </script>
      
    </head>
      
      
    <body>
        輸入你的名字:
    <input type="text" name="myname">
        
    <input type="button" value="Buffao遠(yuǎn)程調(diào)用" onclick="hello($('myname'));"><br>
      
    </body>
    </html>

    說(shuō)明:remoteCall是遠(yuǎn)程調(diào)用方法,demoService是buffalo-service.properties文件的鍵,getHello是被調(diào)用java類方法名,me.value是傳給getHello方法的參數(shù),reply.getResult()是getHello返回的值。

    6.DemoService.java文件
    package demo.buffalo;

    /**
     * 
     * @文件名 demo.buffalo.DemoService.java
     * @作者 chenlb
     * @創(chuàng)建時(shí)間 2007-7-14 下午12:42:17 
     
    */
    public class DemoService {

        
    public String getHello(String name) {
            
    return "Hello , "+name +" 這是第一個(gè)buffalo示例程序";
        }
    }

    7.buffalo-service.properties文件放到WEB-INF/classes/目錄下
    demoService=demo.buffalo.DemoService
    說(shuō)明:框架是通過(guò)此文件來(lái)查找遠(yuǎn)程調(diào)用的類的。

    8.現(xiàn)在可以運(yùn)行了。

    示例下載
    注意:Eclipse項(xiàng)目,文件編碼是UTF-8

    官方地址:
    Buffalo中文論壇:http://groups.google.com/group/amowa
    http://buffalo.sourceforge.net/tutorial.html

    http://confluence.redsaga.com/pages/viewpage.action?pageId=1643

    JavaScript API :http://confluence.redsaga.com/display/BUFFALO/JavaScript+API
    http://www.amowa.net/buffalo/zh/index.html


    xzc 2011-06-16 16:44 發(fā)表評(píng)論
    ]]>
    javaScript通用數(shù)據(jù)類型校驗(yàn)http://m.tkk7.com/xzclog/archive/2008/09/03/226682.htmlxzcxzcWed, 03 Sep 2008 07:01:00 GMThttp://m.tkk7.com/xzclog/archive/2008/09/03/226682.htmlhttp://m.tkk7.com/xzclog/comments/226682.htmlhttp://m.tkk7.com/xzclog/archive/2008/09/03/226682.html#Feedback1http://m.tkk7.com/xzclog/comments/commentRss/226682.htmlhttp://m.tkk7.com/xzclog/services/trackbacks/226682.html閱讀全文

    xzc 2008-09-03 15:01 發(fā)表評(píng)論
    ]]>
    FCKeditor與JSF的整合 http://m.tkk7.com/xzclog/archive/2006/10/14/75159.htmlxzcxzcSat, 14 Oct 2006 09:13:00 GMThttp://m.tkk7.com/xzclog/archive/2006/10/14/75159.htmlhttp://m.tkk7.com/xzclog/comments/75159.htmlhttp://m.tkk7.com/xzclog/archive/2006/10/14/75159.html#Feedback0http://m.tkk7.com/xzclog/comments/commentRss/75159.htmlhttp://m.tkk7.com/xzclog/services/trackbacks/75159.html
    ?? 1.基本配置:

    ????? 知之為知之,不知google之。關(guān)于FCKeditor的基本配置在網(wǎng)上自有高人指點(diǎn),這里我也不多耽誤大家時(shí)間。主要是談下自己當(dāng)初配置的問(wèn)題:
    ??? a.基本路徑:
    ??????? 注意FCKeditor的基本路徑應(yīng)該是/(你的web應(yīng)用名稱)/(放置FCKeditor文件的文件夾名)/
    ??????? 我的目錄結(jié)構(gòu)為:
    ???????
    ??????? 因此,我的基本路徑設(shè)置為:/fck/FCKeditor/

    ???? b.文件瀏覽以及上傳路徑設(shè)置:
    ??????? 我個(gè)人的參考如下:
    ??????
    FCKConfig.LinkBrowser?=?true?;
    FCKConfig.LinkBrowserURL?=?FCKConfig.BasePath?+?'filemanager/browser/default/browser.html?Connector=connectors/jsp/connector'?;
    FCKConfig.LinkBrowserWindowWidth????=?FCKConfig.ScreenWidth?*?0.7?;????????//?70%
    FCKConfig.LinkBrowserWindowHeight????=?FCKConfig.ScreenHeight?*?0.7?;????//?70%

    FCKConfig.ImageBrowser?=?true?;
    FCKConfig.ImageBrowserURL?=?FCKConfig.BasePath?+?'filemanager/browser/default/browser.html?Type=Image
    &Connector=connectors/jsp/connector';
    FCKConfig.ImageBrowserWindowWidth??=?FCKConfig.ScreenWidth?*?0.7?;????//?70%?;
    FCKConfig.ImageBrowserWindowHeight?=?FCKConfig.ScreenHeight?*?0.7?;????//?70%?;

    FCKConfig.FlashBrowser?=?true?;
    FCKConfig.FlashBrowserURL?=?FCKConfig.BasePath?+?'filemanager/browser/default/browser.html?Type=Flash
    &Connector=connectors/jsp/connector'?;
    FCKConfig.FlashBrowserWindowWidth??=?FCKConfig.ScreenWidth?*?0.7?;????//70%?;
    FCKConfig.FlashBrowserWindowHeight?=?FCKConfig.ScreenHeight?*?0.7?;????//70%?;

    FCKConfig.LinkUpload?=?true?;
    FCKConfig.LinkUploadURL?=?FCKConfig.BasePath?+?'filemanager/upload/simpleuploader?Type=File'?;
    FCKConfig.LinkUploadAllowedExtensions????=?""?;????????????//?empty?for?all
    FCKConfig.LinkUploadDeniedExtensions????=?".(php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi)$"?;????//?empty?for?no?one

    FCKConfig.ImageUpload?=?true?;
    FCKConfig.ImageUploadURL?=FCKConfig.BasePath?+?'filemanager/upload/simpleuploader?Type=Image'?;
    FCKConfig.ImageUploadAllowedExtensions????=?".(jpg|gif|jpeg|png)$"?;????????//?empty?for?all
    FCKConfig.ImageUploadDeniedExtensions????=?""?;????????????????????????????//?empty?for?no?one

    FCKConfig.FlashUpload?=?true?;
    FCKConfig.FlashUploadURL?=?FCKConfig.BasePath?+?'filemanager/upload/simpleuploader?Type=Flash'?;
    FCKConfig.FlashUploadAllowedExtensions????=?".(swf|fla)$"?;????????//?empty?for?all
    FCKConfig.FlashUploadDeniedExtensions????=?""?;????????????????????//?empty?for?no?one


    2.與JSF整合。

    ? FCKeditor與JSF整合的最大問(wèn)題,在于需要從JSF環(huán)境中相應(yīng)Bean讀取值賦予給FCKeditor,同時(shí)從FCKeditor里面讀取結(jié)果賦予給相應(yīng)的數(shù)據(jù)持有Bean。由于這一過(guò)程在傳統(tǒng)的JSF標(biāo)簽中是通過(guò)值綁定有框架自動(dòng)完成,因此這里需要我們手動(dòng)來(lái)實(shí)現(xiàn)這一過(guò)程。
    ? 以下要展示的demo由兩部分組成:
    ?? form.jsp顯示編輯內(nèi)容,點(diǎn)擊其submit按鈕跳轉(zhuǎn)至test.jsp,test.jsp調(diào)用FCKeditor對(duì)form.jsp中顯示的已有內(nèi)容進(jìn)行顯示和編輯。編輯完后點(diǎn)擊submit,頁(yè)面將重新跳轉(zhuǎn)到form.jsp,顯示修改后的內(nèi)容。
    ? 其實(shí),這就是一個(gè)很基本的編輯功能,在論壇和blog中都可以看到它的身影。
    ?? 而ContextBean用于持有待編輯的內(nèi)容,它的scope是session范圍。ContextServlet用于讀取FCKeditor修改后的內(nèi)容,并賦予ContextBean中。

    ??? 首先來(lái)看form.jsp
    <body>??
    ????????
    <f:view>
    ????????????
    <h:form>
    ????????????????
    <pre>
    ????????????????
    <h:outputText?value="#{td.name}"?escape="false"></h:outputText>
    ????????????????
    </pre>
    ????????????????????????????????
    <br/>
    ????????????????
    <h:commandButton?value="submit"?action="#{td.submit}"></h:commandButton>
    ????????????
    </h:form>
    ????????
    </f:view>
    ????
    </body>

    ??? 這個(gè)頁(yè)面很簡(jiǎn)單,其中td對(duì)應(yīng)的就是ContextBean,ContextBean.name用于保存編輯內(nèi)容

    package?com.dyerac;

    public?class?ContextBean?{
    ????
    private?String?name;

    ????
    public?String?getName()?{
    ????????
    return?name;
    ????}


    ????
    public?void?setName(String?name)?{
    ????????
    this.name?=?name;
    ????}


    ????
    public?String?submit()?{
    ????????
    ????????
    return?"edit";
    ????}

    }


    下面來(lái)看test.jsp
    ?用過(guò)FCKeditor的都知道,F(xiàn)CKeditor可以通過(guò)三種方式來(lái)調(diào)用:
    ?script, jsp 標(biāo)簽以及java代碼。
    這里,為了方便從ContextBean中讀取name屬性內(nèi)容作為其初始值,我使用了第三種方法
    其中FCKeditor?fck=new?FCKeditor(request,"EditorDefault");初始化FCKeditor,第二個(gè)參數(shù)即為該FCKeditor實(shí)例的id,當(dāng)提交后FCKeditor內(nèi)的內(nèi)容將以該參數(shù)為變量名保存在request中。
    比如,這里我選擇了EditorDefault,所以日后讀取FCKeditor內(nèi)容時(shí),可以通過(guò)以下語(yǔ)句:
    request.getParameter("EditorDefault")

    <body>
    ????????
    <form?action="/fck/servlet/ContextServlet"?method="post"?target="_blank">
    ????????
    <%FCKeditor?fck=new?FCKeditor(request,"EditorDefault");
    ??????????FacesContext?fcg
    =FacesContext.getCurrentInstance();
    ??????????ContextBean?td
    =(ContextBean)fcg.getApplication().getVariableResolver().resolveVariable(fcg,"td");
    ??????????fck.setBasePath(
    "/fck/FCKeditor/");
    ??????????fck.setValue(td.getName());
    ??????????fck.setHeight(
    new?Integer(600).toString());
    ??????????out.print(fck.create());
    ?????????
    %>
    ?????????
    <input?type="submit"?value="Submit">
    ????
    </body>

    ?修改后的結(jié)果以post方式提交給/fck/servlet/ContextServlet,該url對(duì)應(yīng)的即為ContextServlet。
    ContextServlet負(fù)責(zé)讀取FCKeditor里的內(nèi)容,并賦予給session中的ContextBean。doPost()方法用于實(shí)現(xiàn)該功能

    public?void?doPost(HttpServletRequest?request,?HttpServletResponse?response)
    ????????????
    throws?ServletException,?IOException?{
    ????????FacesContext?fcg?
    =?getFacesContext(request,response);
    ????????ContextBean?td?
    =?(ContextBean)?fcg.getApplication()
    ????????????????.getVariableResolver().resolveVariable(fcg,?
    "td");
    ????????String?name
    =new?String(request.getParameter("EditorDefault").getBytes("ISO-8859-1"),"UTF-8");
    ????????td.setName(name);
    ????????RequestDispatcher?rd
    =getServletContext().getRequestDispatcher("/form.faces");
    ????????rd.forward(request,?response);
    ????}

    需要注意兩個(gè)問(wèn)題,
    其一:FCKeditor內(nèi)的中文信息讀取是可能出現(xiàn)亂碼,需要額外的處理:
    ?? String?name=new?String(request.getParameter("EditorDefault").getBytes("ISO-8859-1"),"UTF-8");
    其二:由于servlet處于FacesContext范圍外,因此不能通過(guò)FacesContext.getCurrentInstance()來(lái)得到當(dāng)前FacesContext,因此ContextServlet定義了自己的方法用于獲取FacesContext:

    //?????You?need?an?inner?class?to?be?able?to?call?FacesContext.setCurrentInstance
    //?????since?it's?a?protected?method
    ????private?abstract?static?class?InnerFacesContext?extends?FacesContext
    ????
    {
    ??????
    protected?static?void?setFacesContextAsCurrentInstance(FacesContext?facesContext)?{
    ????????FacesContext.setCurrentInstance(facesContext);
    ??????}

    ????}


    ????
    private?FacesContext?getFacesContext(ServletRequest?request,?ServletResponse?response)?{
    ??????
    //?Try?to?get?it?first
    ??????FacesContext?facesContext?=?FacesContext.getCurrentInstance();
    ??????
    if?(facesContext?!=?null)?return?facesContext;

    ??????FacesContextFactory?contextFactory?
    =?(FacesContextFactory)FactoryFinder.getFactory(FactoryFinder.FACES_CONTEXT_FACTORY);
    ??????LifecycleFactory?lifecycleFactory?
    =?(LifecycleFactory)FactoryFinder.getFactory(FactoryFinder.LIFECYCLE_FACTORY);
    ??????Lifecycle?lifecycle?
    =?lifecycleFactory.getLifecycle(LifecycleFactory.DEFAULT_LIFECYCLE);

    ??????
    //?Either?set?a?private?member?servletContext?=?filterConfig.getServletContext();
    ??????
    //?in?you?filter?init()?method?or?set?it?here?like?this:
    ??????
    //?ServletContext?servletContext?=?((HttpServletRequest)request).getSession().getServletContext();
    ??????
    //?Note?that?the?above?line?would?fail?if?you?are?using?any?other?protocol?than?http
    ??????ServletContext?servletContext?=?((HttpServletRequest)request).getSession().getServletContext();

    ??????
    //?Doesn't?set?this?instance?as?the?current?instance?of?FacesContext.getCurrentInstance
    ??????facesContext?=?contextFactory.getFacesContext(servletContext,?request,?response,?lifecycle);

    ??????
    //?Set?using?our?inner?class
    ??????InnerFacesContext.setFacesContextAsCurrentInstance(facesContext);

    ??????
    //?set?a?new?viewRoot,?otherwise?context.getViewRoot?returns?null
    ??????
    //UIViewRoot?view?=?facesContext.getApplication().getViewHandler().createView(facesContext,?"yourOwnID");
    ??????
    //facesContext.setViewRoot(view);

    ??????
    return?facesContext;
    ????}
    ?

    ?? ContextServlet處理完了FCKeditor內(nèi)容后,將跳轉(zhuǎn)到form.jsp。
    這樣一個(gè)簡(jiǎn)單的編輯功能就完成了。

    3.遺留問(wèn)題:

    ?? 我在上傳文件時(shí)還是會(huì)出現(xiàn)中文亂碼的問(wèn)題,按照其他人說(shuō)的那樣把網(wǎng)頁(yè)的charset=utf-8改成gb2312一樣會(huì)有問(wèn)題,還請(qǐng)各位高手賜教^_^


    另外,關(guān)于整個(gè)demo的源代碼如果大家需要,可以留言給我,我用郵箱發(fā)給您。不足之處,還請(qǐng)各位多多指點(diǎn)



    xzc 2006-10-14 17:13 發(fā)表評(píng)論
    ]]>
    FCKeditor使用說(shuō)明 http://m.tkk7.com/xzclog/archive/2006/10/14/75158.htmlxzcxzcSat, 14 Oct 2006 09:08:00 GMThttp://m.tkk7.com/xzclog/archive/2006/10/14/75158.htmlhttp://m.tkk7.com/xzclog/comments/75158.htmlhttp://m.tkk7.com/xzclog/archive/2006/10/14/75158.html#Feedback0http://m.tkk7.com/xzclog/comments/commentRss/75158.htmlhttp://m.tkk7.com/xzclog/services/trackbacks/75158.html 關(guān)鍵字: ? ????

    開(kāi)發(fā)環(huán)境:
    Tomcat5.5 Eclipse3.2

    FCKeditor 版本 FCKeditor_2.3.1 FCKeditor.Java 2.3

    下載地址: http://www.fckeditor.net/download/default.html

    開(kāi)始:
    新建工程,名稱為 fekeditor
    解壓 FCKeditor_2.3.1 包中的 edit 文件夾到項(xiàng)目中的 WebContent 目錄

    解壓 FCKeditor_2.3.1 包中的 fckconfig.js、fckeditor.js、fckstyles.xml、fcktemplates.xml 文件夾到項(xiàng)目中的 WebContent 目錄

    解壓 FCKeditor-2.3.zip 包中的 \web\WEB-INF\lib 下的兩個(gè) jar 文件到項(xiàng)目的 WebContent\WEB-INF\lib 目錄

    解壓 FCKeditor-2.3.zip 包中的 \src 下的 FCKeditor.tld 文件到項(xiàng)目的 WebContent\WEB-INF 目錄

    刪除 WebContent\edit 目錄下的 _source 文件夾

    修改 web.xml 文件,加入以下內(nèi)容

    代碼
    																<
    																servlet
    																>
    																
    < servlet - name > Connector </ servlet-name>
    <servlet-class>
    com.fredck.FCKeditor.connector.ConnectorServlet
    <
    / servlet - class >
    < init - param >
    < param - name > baseDir </ param-name>
    <!-- 此為文件瀏覽路徑 -->
    <param-value>
    / UserFiles /</ param-value>
    <
    / init - param >
    < init - param >
    < param - name > debug </ param-name>
    <param-value>true<
    / param - value >
    </ init-param>
    <load-on-startup>1<
    / load - on - startup >
    </ servlet> <servlet>
    <servlet-name>SimpleUploader<
    / servlet - name >
    < servlet - class >
    com . fredck . FCKeditor . uploader . SimpleUploaderServlet
    </ servlet-class>
    <init-param>
    <param-name>baseDir<
    / param - name >
    <!-- 此為文件上傳路徑,需要在WebContent 目錄下新建 UserFiles 文件夾 -->
    <!-- 根據(jù)文件的類型還需要新建相關(guān)的文件夾 Image、Flash-->
    <param-value>/UserFiles/</param-value>
    <
    /init-param>
    <init-param>
    <param-name>debug</param-name>
    <param-value>true<
    /param-value>
    </init-param>
    <init-param>
    <!-- 此參數(shù)為是否開(kāi)啟上傳功能 -->
    <param-name>enabled<
    /param-name>
    <param-value>false</param-value>
    <
    /init-param>
    <init-param>
    <param-name>AllowedExtensionsFile</param-name>
    <param-value><
    /param-value>
    </init-param>
    <init-param> <!-- 此參數(shù)為文件過(guò)濾,以下的文件類型都不可以上傳 -->
    <param-name>DeniedExtensionsFile<
    /param-name>
    <param-value>
    php|php3|php5|phtml|asp|aspx|ascx|jsp|cfm|cfc|pl|bat|exe|dll|reg|cgi
    </param-value>
    <
    /init-param>
    <init-param>
    <param-name>AllowedExtensionsImage</param-name>
    <param-value>jpg|gif|jpeg|png|bmp<
    /param-value>
    </init-param>
    <init-param>
    <param-name>DeniedExtensionsImage<
    /param-name>
    <param-value></param-value>
    <
    /init-param>
    <init-param>
    <param-name>AllowedExtensionsFlash</param-name>
    <param-value>swf|fla<
    /param-value>
    </init-param>
    <init-param>
    <param-name>DeniedExtensionsFlash<
    /param-name>
    <param-value></param-value>
    <
    /init-param>
    <load-on-startup>1</load-on-startup>
    <
    /servlet><servlet-mapping>
    <servlet-name>Connector</servlet-name>
    <url-pattern>
    /editor/filemanager/browser/default/connectors/jsp/connector
    </url-pattern>
    <
    /servlet-mapping><servlet-mapping>
    <servlet-name>SimpleUploader</servlet-name>
    <url-pattern>
    /editor/filemanager/upload/simpleuploader
    </url-pattern>
    <
    /servlet-mapping>

    新建一個(gè)提交頁(yè) jsp1.jsp 文件和一個(gè)接收頁(yè) jsp2.jsp 文件

    jsp1.jsp 代碼如下:

    代碼
    <%@ page contentType = "text/html;charset=UTF-8" language = "java" %>
    
    <%
    @tagliburi="/WEB-INF/FCKeditor.tld"prefix="fck"%><html>
    <head>
    <title>Test</title>
    <
    /head><body>
    <FORMaction="jsp2.jsp">
    <fck:editorid="testfck"basePath="/fekeditor/"
    height="100%"
    skinPath="/fekeditor/editor/skins/default/"
    toolbarSet="Default"
    imageBrowserURL="/fekeditor/editor/filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector"
    linkBrowserURL="/fekeditor/editor/filemanager/browser/default/browser.html?Connector=connectors/jsp/connector"
    flashBrowserURL="/fekeditor/editor/filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/jsp/connector"
    imageUploadURL="/fekeditor/editor/filemanager/upload/simpleuploader?Type=Image"
    linkUploadURL="/fekeditor/editor/filemanager/upload/simpleuploader?Type=File"
    flashUploadURL="/fekeditor/editor/filemanager/upload/simpleuploader?Type=Flash">
    </fck:editor>
    <input type="submit"
    />
    </FORM>
    <
    /body>
    </html>jsp2.jsp 代碼如下:<html>
    <head>
    <title>TEST<
    /title>
    </head> <body>
    <%=request.getParameter( "testfck" )%>
    <
    /body>
    </html>

    在 WebContent 目錄下新建 UserFiles 文件夾,在此文件夾下新建 File,Image,Flash 三個(gè)文件夾。

    ok現(xiàn)在運(yùn)行一下看看吧!



    xzc 2006-10-14 17:08 發(fā)表評(píng)論
    ]]>
    FCKeditor在線編輯器的使用http://m.tkk7.com/xzclog/archive/2006/10/11/74629.htmlxzcxzcWed, 11 Oct 2006 09:19:00 GMThttp://m.tkk7.com/xzclog/archive/2006/10/11/74629.htmlhttp://m.tkk7.com/xzclog/comments/74629.htmlhttp://m.tkk7.com/xzclog/archive/2006/10/11/74629.html#Feedback0http://m.tkk7.com/xzclog/comments/commentRss/74629.htmlhttp://m.tkk7.com/xzclog/services/trackbacks/74629.html

    試用了一下FCKeditor,根據(jù)網(wǎng)上的文章小結(jié)一下:
    1.下載
    FCKeditor.java 2.3 (FCKeditot for java)
    FCKeditor 2.2 (FCKeditor基本文件)

    2.建立項(xiàng)目:tomcat/webapps/TestFCKeditor.

    3.將FCKeditor2.2解壓縮,將整個(gè)目錄FCKeditor復(fù)制到項(xiàng)目的根目錄下,
    目錄結(jié)構(gòu)為:tomcat/webapps/TestFCKeditor/FCKeditor
    然后將FCKeditor-2.3.zip(java)壓縮包中\(zhòng)web\WEB-INF\lib\目錄下的兩個(gè)jar文件拷到項(xiàng)目的\WEB-INF\lib\目錄下。把其中的src目錄下的FCKeditor.tld文件copy到TestFCKedit/FCKeitor/WEB-INF/下

    4.將FCKeditor-2.3.zip壓縮包中\(zhòng)web\WEB-INF\目錄下的web.xml文件合并到項(xiàng)目的\WEB-INF\目錄下的web.xml文件中。

    5. 修改合并后的web.xml文件,將名為SimpleUploader的Servlet的enabled參數(shù)值改為true,
    以允許上傳功能,Connector Servlet的baseDir參數(shù)值用于設(shè)置上傳文件存放的位置。
    添加標(biāo)簽定義:
    <taglib>
    <taglib-uri>/TestFCKeditor</taglib-uri>
    <taglib-location>/WEB-INF/FCKeditor.tld</taglib-location>
    </taglib>

    運(yùn)行圖:

    6. 上面文件中兩個(gè)servlet的映射分別為:/editor/filemanager/browser/default/connectors/jsp/connector
    和/editor/filemanager/upload/simpleuploader,需要在兩個(gè)映射前面加上/FCKeditor,
    即改為/FCKeditor/editor/filemanager/browser/default/connectors/jsp/connector和
    /FCKeditor/editor/filemanager/upload/simpleuploader。

    7.進(jìn)入skin文件夾,如果你想使用fckeditor默認(rèn)的這種奶黃色,
    那就把除了default文件夾外的另兩個(gè)文件夾直接刪除.

    8.刪除/FCKeditor/目錄下除fckconfig.js, fckeditor.js, fckstyles.xml, fcktemplates.xml四個(gè)文件以外的所有文件
    刪除目錄/editor/_source,
    刪除/editor/filemanager/browser/default/connectors/下的所有文件
    刪除/editor/filemanager/upload/下的所有文件
    刪除/editor/lang/下的除了fcklanguagemanager.js, en.js, zh.js, zh-cn.js四個(gè)文件的所有文件

    9.打開(kāi)/FCKeditor/fckconfig.js
    修改 FCKConfig.DefaultLanguage = 'zh-cn' ;
    把FCKConfig.LinkBrowserURL等的值替換成以下內(nèi)容:
    FCKConfig.LinkBrowserURL
    = FCKConfig.BasePath + "filemanager/browser/default/browser.html?Connector=connectors/jsp/connector" ;

    FCKConfig.ImageBrowserURL
    = FCKConfig.BasePath + "filemanager/browser/default/browser.html?Type=Image&Connector=connectors/jsp/connector" ;

    FCKConfig.FlashBrowserURL
    = FCKConfig.BasePath + "filemanager/browser/default/browser.html?Type=Flash&Connector=connectors/jsp/connector" ;


    FCKConfig.LinkUploadURL = FCKConfig.BasePath + 'filemanager/upload/simpleuploader?Type=File' ;
    FCKConfig.FlashUploadURL = FCKConfig.BasePath + 'filemanager/upload/simpleuploader?Type=Flash' ;
    FCKConfig.ImageUploadURL = FCKConfig.BasePath + 'filemanager/upload/simpleuploader?Type=Image' ;

    10.其它
    fckconfig.js總配置文件,可用記錄本打開(kāi),修改后將文件存為utf-8 編碼格式。找到:

    FCKConfig.TabSpaces = 0 ; 改為FCKConfig.TabSpaces = 1 ; 即在編輯器域內(nèi)可以使用Tab鍵。

    如果你的編輯器還用在網(wǎng)站前臺(tái)的話,比如說(shuō)用于留言本或是日記回復(fù)時(shí),那就不得不考慮安全了,
    在前臺(tái)千萬(wàn)不要使用Default的toolbar,要么自定義一下功能,要么就用系統(tǒng)已經(jīng)定義好的Basic,
    也就是基本的toolbar,找到:
    FCKConfig.ToolbarSets["Basic"] = [
    ['Bold','Italic','-','OrderedList','UnorderedList','-',/*'Link',*/'Unlink','-','Style','FontSize','TextColor','BGColor','-',
    'Smiley','SpecialChar','Replace','Preview'] ] ;
    這是改過(guò)的Basic,把圖像功能去掉,把添加鏈接功能去掉,因?yàn)閳D像和鏈接和flash和圖像按鈕添加功能都能讓前臺(tái)
    頁(yè)直接訪問(wèn)和上傳文件, fckeditor還支持編輯域內(nèi)的鼠標(biāo)右鍵功能。

    FCKConfig.ContextMenu = ['Generic',/*'Link',*/'Anchor',/*'Image',*/'Flash','Select','Textarea','Checkbox','Radio','TextField','HiddenField',
    /*'ImageButton',*/'Button','BulletedList','NumberedList','TableCell','Table','Form'] ;

    這也是改過(guò)的把鼠標(biāo)右鍵的“鏈接、圖像,F(xiàn)LASH,圖像按鈕”功能都去掉。

      找到: FCKConfig.FontNames = 'Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;
    加上幾種我們常用的字體
    FCKConfig.FontNames
    = '宋體;黑體;隸書(shū);楷體_GB2312;Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;

    7.添加文件 /TestFCKeditor/test.jsp:
    <%@ page language="java" import="com.fredck.FCKeditor.*" %>
    <%@ taglib uri="/TestFCKeditor" prefix="FCK" %>
    <script type="text/javascript" src="/TestFCKeditor/FCKeditor/fckeditor.js"></script>

    <%--
    三種方法調(diào)用FCKeditor
    1.FCKeditor自定義標(biāo)簽 (必須加頭文件 <%@ taglib uri="/TestFCKeditor" prefix="FCK" %> )
    2.script腳本語(yǔ)言調(diào)用 (必須引用 腳本文件 <script type="text/javascript" src="/TestFCKeditor/FCKeditor/fckeditor.js"></script> )
    3.FCKeditor API 調(diào)用 (必須加頭文件 <%@ page language="java" import="com.fredck.FCKeditor.*" %> )
    --%>

    <%--
    <form action="show.jsp" method="post" target="_blank">
    <FCK:editor id="content" basePath="/TestFCKeditor/FCKeditor/"
    width="700"
    height="500"
    skinPath="/TestFCKeditor/FCKeditor/editor/skins/silver/"
    toolbarSet = "Default"
    >
    input
    </FCK:editor>
    <input type="submit" value="Submit">
    </form>
    --%>

    <form action="show.jsp" method="post" target="_blank">
    <table border="0" width="700"><tr><td>
    <textarea id="content" name="content" style="WIDTH: 100%; HEIGHT: 400px">input</textarea>
    <script type="text/javascript">
    var oFCKeditor = new FCKeditor('content') ;
    oFCKeditor.BasePath = "/TestFCKeditor/FCKeditor/" ;
    oFCKeditor.Height = 400;
    oFCKeditor.ToolbarSet = "Default" ;
    oFCKeditor.ReplaceTextarea();
    </script>
    <input type="submit" value="Submit">
    </td></tr></table>
    </form>

    <%--
    <form action="show.jsp" method="post" target="_blank">
    <%
    FCKeditor oFCKeditor ;
    oFCKeditor = new FCKeditor( request, "content" ) ;
    oFCKeditor.setBasePath( "/TestFCKeditor/FCKeditor/" ) ;
    oFCKeditor.setValue( "input" );
    out.println( oFCKeditor.create() ) ;
    %>
    <br>
    <input type="submit" value="Submit">
    </form>
    --%>

    添加文件/TestFCKeditor/show.jsp:
    <%
    String content = request.getParameter("content");
    out.print(content);
    %>

    8.瀏覽http://localhost:8080/TestFCKeditor/test.jsp
    ok!



    xzc 2006-10-11 17:19 發(fā)表評(píng)論
    ]]>
    祥解WEB應(yīng)用的部署文件web.xmlhttp://m.tkk7.com/xzclog/archive/2006/08/10/62796.htmlxzcxzcThu, 10 Aug 2006 07:10:00 GMThttp://m.tkk7.com/xzclog/archive/2006/08/10/62796.htmlhttp://m.tkk7.com/xzclog/comments/62796.htmlhttp://m.tkk7.com/xzclog/archive/2006/08/10/62796.html#Feedback0http://m.tkk7.com/xzclog/comments/commentRss/62796.htmlhttp://m.tkk7.com/xzclog/services/trackbacks/62796.html    在分析web.xml文檔之前我想先說(shuō)一下web.xml中根元素<web-app>各子元素的順序問(wèn)題,因?yàn)樵趙eb.xml中元素定義的先后順序是不能顛倒的(除非web.xml文件中使用XML Schema,本文不做討論),否則Tomcat服務(wù)器可能拋出SAXParseException。
        順序如下:
                          <web-app>
                          <display-name>
                          <description>
                          <distributable>
                          <context-param>
                          <filter>
                          <filter-mapping>
                         <listener>
                          <servlet>
                          <servlet-mapping>
                          <session-config>
                          <mime-mapping>
                          <welcome-file-list>
                          <error-page>
                          <taglib>
                         <resource-env-ref>
                          <resource-ref>
                          <security-constraint>
                          <login-config>
                          <security-role>
                          <env-entry>
                          <ejb-ref>
                          <ejb-local-ref>
    web.xml中的開(kāi)頭幾行是固定的,它定義了該文件的字符編碼,XML版本以及引用的DTD文件。
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "在web.xml中頂層元素為<web-app>,其他所有的子元素都必須定義在<web-app>內(nèi)

    <display-name>元素定義這個(gè)web應(yīng)用的名字,Java Web 服務(wù)器的Web管理工具將用這個(gè)名字來(lái)標(biāo)志W(wǎng)eb應(yīng)用。

    <description>元素用來(lái)聲明Web應(yīng)用的描述信息

    <context-param>元素用來(lái)配置外部引用的,在servlet中如果要獲得該元素中配置的值,String param-value = getServletContext().getInitParameter("param-name")

    <filter>
            <filter-name>SampleFilter</filter-name>
            <filter-class>com.lpdev.SampleFilter</filter-class>
    </filter>
    <filter-mapping>
            <filter-name>SampleFilter</filter-name>
            <url-pattern>*.jsp</url-pattern>
    </filter-mapping>
    以上是配置了一個(gè)servlet過(guò)濾器,對(duì)于servlet容器收到的客戶請(qǐng)求以及發(fā)出的響應(yīng)結(jié)果,servlet都能檢查和修改其中的信息,以上代碼指名當(dāng)客戶請(qǐng)求訪問(wèn)Web應(yīng)用中的所有JSP文件時(shí),將觸發(fā)SampleFilter過(guò)濾器工作,具體的過(guò)濾事務(wù)在由<filter-class>中指定的類來(lái)完成

     <servlet>
      <servlet-name>IncludeServlet</servlet-name>
      <servlet-class>com.lpdev.IncludeServlet</servlet-class>
      
      <init-param>
         <param-name>copyright</param-name>
         <param-value>/foot.jspf</param-value>
         <load-on-startup>1</load-on-startup>
      </init-param>
     </servlet>
    配置Servlet,<servlet-name>是servlet的名字,<servlet-class>是實(shí)現(xiàn)這個(gè)Servlet的類,<init-param>定義Servlet的初始化參數(shù)(參數(shù)名和參數(shù)值),一個(gè)Servlet可以有多個(gè)<init-param>,在Servlet類中通過(guò)getInitParameter(String name)方法訪問(wèn)初始化參數(shù)

     <servlet-mapping>
      <servlet-name>IncludeServlet</servlet-name>
      <url-pattern>/IncludeServlet</url-pattern>
     </servlet-mapping>
    配置Servlet映射,<servlet-mapping>元素用來(lái)設(shè)定客戶訪問(wèn)某個(gè)Servlet的URL,這里只需給出對(duì)于整個(gè)web應(yīng)用的相對(duì)的URL路徑,<url-pattern>中的“/”表示開(kāi)始于Web應(yīng)用的根目錄例如,如果你在你本地機(jī)器上使用Tomcat4.1.x,并且創(chuàng)建了名為“myapp”的應(yīng)用程序,<url-pattern>/IncludeServlet</url-pattern>該Servlet的完整web地址就是
    http://localhost:8080/myapp/IncludeServlet

    <session-config>元素用來(lái)設(shè)定HttpSession的生命周期,該元素只有一個(gè)<session-timeout>屬性,時(shí)間單位是“秒”。

    <welcome-file-list>當(dāng)用戶訪問(wèn)web時(shí),如果僅僅給出web應(yīng)用的Root URL,沒(méi)有指定具體文件名,容器調(diào)用該配置,該元素可以包含多個(gè)<welcome-file>屬性。

    <taglib>元素用來(lái)設(shè)置web引用的tag library,例示定義了一個(gè)“/mytaglib”標(biāo)簽庫(kù),它對(duì)應(yīng)的tld文件為:/WEB_INF/mytaglib.tld
    <taglib>
        <taglib-url>/mytaglib</taglib-url>
        <taglib-locationg>/WEB-INF/mytaglib.tld</taglib-location>
    </taglib>

    <resource-ref>如果web應(yīng)用由Servlet容器管理的某個(gè)JNDI Resource,必須在web.xml中聲明對(duì)這個(gè)JNDI Resource的引用。
    <resource-ref>
        <description>DB Connection</description> //說(shuō)明
        <res-ref-name>jdbc/sampleDB</res-ref-name> //引用資源的JNDI名字
        <res-type>javax.sql.DataSource</res-type> //引用資源的類名字
        <res-auth>Container</res-auth> //管理引用資源的Manager
    </resource-ref>

    <security-constraint>用來(lái)為Web應(yīng)用定義安全約束
     <security-constraint>
        <web-resource-collection>//聲明受保護(hù)的web資源
           <web-resource-name>ResourceServlet</web-resource-name>//標(biāo)識(shí)受保護(hù)web資源
           <url-pattern>/ResourceServlet</url-pattern>//指定受保護(hù)的URL路徑
           <http-method>GET</http-method>//指定受保護(hù)的方法
           <http-method>POST</http-method>
        </web-resource-collection>
        <auth-constraint>//可以訪問(wèn)受保護(hù)資源的角色
           <description>this applies only to admin secrity role</description>
           <role-name>admin</role-name>
        </auth-constraint>
        <user-data-constraint>
           <transport-guarantee>NONE</transport-guarantee>
        </user-data-constraint>
     </security-constraint>

    <login-config>元素指定當(dāng)Web客戶訪問(wèn)受保護(hù)資源時(shí),系統(tǒng)彈出的登陸對(duì)話框的類型。例示配置了基于表單驗(yàn)證的登陸界面
    <login-config>
        <auth-method>FORM</auth-method>//BASIC(基本驗(yàn)證法),DIGEST(摘要驗(yàn)證),F(xiàn)ORM(表單驗(yàn)證)
        <real-name>設(shè)定安全域的名稱</realname>
        <form-login-config>
            <form-login-page>/login.jsp</form-login-page>
            <form-error-page>/error.jsp</form-error-page>
        </form-login-config>

    <security-role>指明這個(gè)Web應(yīng)用引用的所有角色名字
    <security-role>
        <description>描述</description>
        <role-name>admin</role-name>
    </security-role>



    xzc 2006-08-10 15:10 發(fā)表評(píng)論
    ]]>
    主站蜘蛛池模板: 亚洲视频在线观看免费| 99久久人妻精品免费一区| 日本不卡高清中文字幕免费| 91亚洲国产成人久久精品| 成年人网站免费视频| 亚洲一卡2卡4卡5卡6卡在线99 | 久久久久免费看成人影片| 久久久久久a亚洲欧洲AV| 1000部无遮挡拍拍拍免费视频观看 | 亚洲精品tv久久久久| 久99久无码精品视频免费播放| 亚洲综合另类小说色区| a视频在线观看免费| 亚洲最新永久在线观看| 久久久高清免费视频| 18禁亚洲深夜福利人口| 亚洲国产精品成人久久蜜臀 | 国产亚洲福利一区二区免费看| 精品在线视频免费| 亚洲一区精品无码| 67pao强力打造国产免费| 亚洲乱理伦片在线观看中字| mm1313亚洲精品国产| 免费看少妇高潮成人片| 亚洲黄色在线观看| 免费国产成人高清在线观看麻豆| 久草免费福利在线| 亚洲娇小性xxxx色| 亚洲黄黄黄网站在线观看| 亚洲一区免费观看| 在线观看国产一区亚洲bd| 中文字幕精品亚洲无线码一区| 国产h视频在线观看网站免费| 天天综合亚洲色在线精品| 亚洲第一福利网站| 国产一级淫片免费播放| 精品在线免费观看| 日本亚洲高清乱码中文在线观看| 亚洲AV综合色区无码一区| 午夜免费不卡毛片完整版| 日本人成在线视频免费播放|