日韩三级中文字幕,亚洲视频在线看,色中色在线视频http://www.aygfsteel.com/xzclog/category/17326.htmlzh-cnTue, 24 Jul 2012 21:03:51 GMTTue, 24 Jul 2012 21:03:51 GMT60avaScript世界的一等公民 - 函數http://www.aygfsteel.com/xzclog/archive/2012/07/24/383831.htmlxzcxzcTue, 24 Jul 2012 05:45:00 GMThttp://www.aygfsteel.com/xzclog/archive/2012/07/24/383831.htmlhttp://www.aygfsteel.com/xzclog/comments/383831.htmlhttp://www.aygfsteel.com/xzclog/archive/2012/07/24/383831.html#Feedback0http://www.aygfsteel.com/xzclog/comments/commentRss/383831.htmlhttp://www.aygfsteel.com/xzclog/services/trackbacks/383831.html閱讀全文

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

1、重新生成該靜態頁面,優點是用戶訪問時頁面上的肉容可以實現全靜態,不與服務器程序及數據庫后端打交道!缺點是每次用戶對頁面任何部分更新都必須重新生成。

2、js調用請求動態內容,優點是靜態頁面只生成一次,動態部分才動態加載,卻點是服務器端要用輸出一段js代碼并用js代碼輸出網頁內容,也不利于搜索引擎收錄。

3、ajax調用動態內容,和js基本相似,只是與服務器交互的方式不同!并且頁面顯示不會受到因動態調用速度慢而影響整個頁面的加載速度!至于ajax不利于搜索收錄,當然在《ajax in acation》等相關書籍中也介紹有變向的解決方案!

4、在服務器端ssl動態內容,用服務器端優化及緩存解決是時下最流行的方法!

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

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

<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>

然后我們通過調用此函數獲取對應參數值:

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


以此獲取url串中所帶的同名參數

二、正則分析法。

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("參數名1"));   
alert(GetQueryString("參數名2"));   
alert(GetQueryString("參數名3"));

xzc 2011-12-12 17:15 發表評論
]]>
Java Cookie 中文亂碼解決方法 http://www.aygfsteel.com/xzclog/archive/2011/10/03/359956.htmlxzcxzcMon, 03 Oct 2011 03:29:00 GMThttp://www.aygfsteel.com/xzclog/archive/2011/10/03/359956.htmlhttp://www.aygfsteel.com/xzclog/comments/359956.htmlhttp://www.aygfsteel.com/xzclog/archive/2011/10/03/359956.html#Feedback0http://www.aygfsteel.com/xzclog/comments/commentRss/359956.htmlhttp://www.aygfsteel.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() 只有一個參數的已經過時了,現在可以設置編碼格式, 取cookie值的時候 也不用解碼了。

     



    xzc 2011-10-03 11:29 發表評論
    ]]>
    web.xml中load-on-startup的作用http://www.aygfsteel.com/xzclog/archive/2011/09/29/359789.htmlxzcxzcThu, 29 Sep 2011 07:22:00 GMThttp://www.aygfsteel.com/xzclog/archive/2011/09/29/359789.htmlhttp://www.aygfsteel.com/xzclog/comments/359789.htmlhttp://www.aygfsteel.com/xzclog/archive/2011/09/29/359789.html#Feedback1http://www.aygfsteel.com/xzclog/comments/commentRss/359789.htmlhttp://www.aygfsteel.com/xzclog/services/trackbacks/359789.html如下一段配置,熟悉DWR的再熟悉不過了:
    <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>,那么這個配置有什么作用呢?

    貼一段英文原汁原味的解釋如下:
    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.

    翻譯過來的意思大致如下:
    1)load-on-startup元素標記容器是否在啟動的時候就加載這個servlet(實例化并調用其init()方法)。

    2)它的值必須是一個整數,表示servlet應該被載入的順序

    2)當值為0或者大于0時,表示容器在應用啟動時就加載并初始化這個servlet;

    3)當值小于0或者沒有指定時,則表示容器在該servlet被選擇時才會去加載。

    4)正數的值越小,該servlet的優先級越高,應用啟動時就越先加載。

    5)當值相同時,容器就會自己選擇順序來加載。

    所以,<load-on-startup>x</load-on-startup>,中x的取值1,2,3,4,5代表的是優先級,而非啟動延遲時間。

    如下題目:

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

    a.默認起始頁

    b.servlet啟動延遲時間定義

    c.error處理頁面

    d.jsp文件改動后重新載入時間

    答案:b,d

    通常大多數Servlet是在用戶第一次請求的時候由應用服務器創建并初始化,但<load-on-startup>n</load-on-startup>   可以用來改變這種狀況,根據自己需要改變加載的優先級!



    xzc 2011-09-29 15:22 發表評論
    ]]>
    js 高級編程http://www.aygfsteel.com/xzclog/archive/2011/07/09/353978.htmlxzcxzcSat, 09 Jul 2011 03:34:00 GMThttp://www.aygfsteel.com/xzclog/archive/2011/07/09/353978.htmlhttp://www.aygfsteel.com/xzclog/comments/353978.htmlhttp://www.aygfsteel.com/xzclog/archive/2011/07/09/353978.html#Feedback2http://www.aygfsteel.com/xzclog/comments/commentRss/353978.htmlhttp://www.aygfsteel.com/xzclog/services/trackbacks/353978.html

    研究發現:屬性(變量)可分為三類(對象屬性、全局變量和局部變量)
    對象屬性:聲明時以“this.”開頭,只能被“類的實例”即對象所調用,不能被“類內部(對外不對內)”調用;全局變量:聲明時直接以變量名開頭,可以任意調用(對內對外);局部變量:只能被

    “類內部(對內不對外)”調用。

     

    JS函數的聲明與訪問原理

    <script type="text/javascript">  
    //類  
    var testClass = function(){  
      //對象屬性(對外不對內,類調用)  
      this.age ="25";  
      //全局變量(對內對外)  
      name="jack";  
      //局部變量(對內不對外)
      var address = "beijing";
        
      //全局函數(對內對外)  
      add = function(a,b){  
        //可訪問:全局變量和局部變量  
        multiply(a,b);  
        return a+b;  
      }  
      //實例函數(由類的對象調用)  
      this.minus = function(a,b){  
        //可以訪問:對象屬性、全局變量和局部變量  
        return a-b;  
      }  
      //局部函數(內部直接調用)  
      var multiply = function(a,b){  
        //只能訪問:全局變量和局部變量  
        return a*b;  
      }  
    }  
     
     
    //類函數(由類名直接調用)  
    testClass.talk= function(){  
      //只能訪問:全局變量和全局函數  
      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));
      }  
    }  
     
     
    //原型函數(由類的對象調用)  
    testClass.prototype.walk = function(){  
      //只能訪問:全局變量和全局函數  
      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> 


    下面看看如何調用:

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



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

    早起的國內互聯網都使用GBK編碼,久之,所有項目都以GBK來編碼了。對于J2EE項目,為了減少編碼的干擾通常都是設置一個編碼的Filter,強制將Request/Response編碼改為GBK。例如一個Spring的常見配置如下:

     

    <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>
    

    毫無疑問,這在GBK編碼的頁面訪問、提交數據時是沒有亂碼問題的。但是遇到Ajax就不一樣了。Ajax強制將中文內容進行UTF-8編碼,這樣導致進入后端后使用GBK進行解碼時發生亂碼。網上的所謂的終極解決方案都是扯淡或者過于復雜,例如下面的文章:

    這樣的文章很多,顯然:

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

    如果提交數據的時候能夠告訴后端傳輸的編碼信息是否就可以避免這種問題?比如Ajax請求告訴后端是UTF-8,其它請求告訴后端是GBK,這樣后端分別根據指定的編碼進行解碼是不是就解決問題了。

    有兩個問題:

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

    解決了上述問題,來看具體實現方案。 列一段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;
    
    /** 自定義編碼過濾器
     * @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就使用此編碼進行設置Request編碼,以后參數按照此編碼進行解析,例如如果是Ajax就傳入UTF-8,如果是普通的GBK請求則無視此參數。
    • 如果無視此參數,則按照web.xml中配置的編碼規則進行反編碼,如果是GBK就按照GBK規則解析。
    • 對于輸出編碼同樣使用上述規則。需要輸出編碼依賴輸入編碼,也就是說如果有一個_output_encode的輸出編碼,則同時需要有一個_input_encode編碼來指定輸入編碼。當然你可以改造成不依賴輸入編碼。
    • 完全兼容Spring的org.springframework.web.filter.CharacterEncodingFilter編碼規則,只需要替換類即可。
    • 沒有繼承org.springframework.web.filter.CharacterEncodingFilter類的原因是,org.springframework.web.filter.CharacterEncodingFilter里面的encoding參數和forceEncoding參數是private,子類無法使用。在有_input_encode而無_output_encode的時候想依然保持Spring的Response解析規則的話無法做到,所以將里面的代碼拷貝過來使用。(為了展示方便,注釋都刪掉了)
    • 正則表達式可以改進成只需要匹配一次,從而可以提高一點點效率。
    • 所有后端請求將無視編碼的存在,前端Ajax的GET/POST請求也將無視編碼的存在,只是在URL地址中加上一個_input_encode=UTF-8的參數。僅此而已。
    • 如果想輸出的編碼也是UTF-8,比如手機端請求、跨站請求等,則需要URL地址參數_input_encode=UTF-8&_output_encode=UTF-8。
    • 對于POST請求,編碼參數不能寫在body里面,否則無法解析。
    • 顯然,這種終極解決方案,在任何編碼中都可以解決,GBK/UTF-8/ISO8859-1等編碼任何組合都可以實現。
    • 唯一局限性是,此解決方案限制在J2EE項目中,其它平臺不知是否有類似Filter這樣的組件能夠設置編碼的概念。



    xzc 2011-06-21 11:54 發表評論
    ]]>
    Buffalo Ajax框架使用 http://www.aygfsteel.com/xzclog/archive/2011/06/16/352439.htmlxzcxzcThu, 16 Jun 2011 08:44:00 GMThttp://www.aygfsteel.com/xzclog/archive/2011/06/16/352439.htmlhttp://www.aygfsteel.com/xzclog/comments/352439.htmlhttp://www.aygfsteel.com/xzclog/archive/2011/06/16/352439.html#Feedback0http://www.aygfsteel.com/xzclog/comments/commentRss/352439.htmlhttp://www.aygfsteel.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應用程序里的lib

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

    4.web.xml內容
    <?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>第一個 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遠程調用" onclick="hello($('myname'));"><br>
      
    </body>
    </html>

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

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

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

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

    7.buffalo-service.properties文件放到WEB-INF/classes/目錄下
    demoService=demo.buffalo.DemoService
    說明:框架是通過此文件來查找遠程調用的類的。

    8.現在可以運行了。

    示例下載
    注意:Eclipse項目,文件編碼是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 發表評論
    ]]>
    javaScript通用數據類型校驗http://www.aygfsteel.com/xzclog/archive/2008/09/03/226682.htmlxzcxzcWed, 03 Sep 2008 07:01:00 GMThttp://www.aygfsteel.com/xzclog/archive/2008/09/03/226682.htmlhttp://www.aygfsteel.com/xzclog/comments/226682.htmlhttp://www.aygfsteel.com/xzclog/archive/2008/09/03/226682.html#Feedback1http://www.aygfsteel.com/xzclog/comments/commentRss/226682.htmlhttp://www.aygfsteel.com/xzclog/services/trackbacks/226682.html閱讀全文

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

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

    ???? b.文件瀏覽以及上傳路徑設置:
    ??????? 我個人的參考如下:
    ??????
    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整合的最大問題,在于需要從JSF環境中相應Bean讀取值賦予給FCKeditor,同時從FCKeditor里面讀取結果賦予給相應的數據持有Bean。由于這一過程在傳統的JSF標簽中是通過值綁定有框架自動完成,因此這里需要我們手動來實現這一過程。
    ? 以下要展示的demo由兩部分組成:
    ?? form.jsp顯示編輯內容,點擊其submit按鈕跳轉至test.jsp,test.jsp調用FCKeditor對form.jsp中顯示的已有內容進行顯示和編輯。編輯完后點擊submit,頁面將重新跳轉到form.jsp,顯示修改后的內容。
    ? 其實,這就是一個很基本的編輯功能,在論壇和blog中都可以看到它的身影。
    ?? 而ContextBean用于持有待編輯的內容,它的scope是session范圍。ContextServlet用于讀取FCKeditor修改后的內容,并賦予ContextBean中。

    ??? 首先來看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>

    ??? 這個頁面很簡單,其中td對應的就是ContextBean,ContextBean.name用于保存編輯內容

    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";
    ????}

    }


    下面來看test.jsp
    ?用過FCKeditor的都知道,FCKeditor可以通過三種方式來調用:
    ?script, jsp 標簽以及java代碼。
    這里,為了方便從ContextBean中讀取name屬性內容作為其初始值,我使用了第三種方法
    其中FCKeditor?fck=new?FCKeditor(request,"EditorDefault");初始化FCKeditor,第二個參數即為該FCKeditor實例的id,當提交后FCKeditor內的內容將以該參數為變量名保存在request中。
    比如,這里我選擇了EditorDefault,所以日后讀取FCKeditor內容時,可以通過以下語句:
    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>

    ?修改后的結果以post方式提交給/fck/servlet/ContextServlet,該url對應的即為ContextServlet。
    ContextServlet負責讀取FCKeditor里的內容,并賦予給session中的ContextBean。doPost()方法用于實現該功能

    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);
    ????}

    需要注意兩個問題,
    其一:FCKeditor內的中文信息讀取是可能出現亂碼,需要額外的處理:
    ?? String?name=new?String(request.getParameter("EditorDefault").getBytes("ISO-8859-1"),"UTF-8");
    其二:由于servlet處于FacesContext范圍外,因此不能通過FacesContext.getCurrentInstance()來得到當前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內容后,將跳轉到form.jsp。
    這樣一個簡單的編輯功能就完成了。

    3.遺留問題:

    ?? 我在上傳文件時還是會出現中文亂碼的問題,按照其他人說的那樣把網頁的charset=utf-8改成gb2312一樣會有問題,還請各位高手賜教^_^


    另外,關于整個demo的源代碼如果大家需要,可以留言給我,我用郵箱發給您。不足之處,還請各位多多指點



    xzc 2006-10-14 17:13 發表評論
    ]]>
    FCKeditor使用說明 http://www.aygfsteel.com/xzclog/archive/2006/10/14/75158.htmlxzcxzcSat, 14 Oct 2006 09:08:00 GMThttp://www.aygfsteel.com/xzclog/archive/2006/10/14/75158.htmlhttp://www.aygfsteel.com/xzclog/comments/75158.htmlhttp://www.aygfsteel.com/xzclog/archive/2006/10/14/75158.html#Feedback0http://www.aygfsteel.com/xzclog/comments/commentRss/75158.htmlhttp://www.aygfsteel.com/xzclog/services/trackbacks/75158.html 關鍵字: ? ????

    開發環境:
    Tomcat5.5 Eclipse3.2

    FCKeditor 版本 FCKeditor_2.3.1 FCKeditor.Java 2.3

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

    開始:
    新建工程,名稱為 fekeditor
    解壓 FCKeditor_2.3.1 包中的 edit 文件夾到項目中的 WebContent 目錄

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

    解壓 FCKeditor-2.3.zip 包中的 \web\WEB-INF\lib 下的兩個 jar 文件到項目的 WebContent\WEB-INF\lib 目錄

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

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

    修改 web.xml 文件,加入以下內容

    代碼
    																<
    																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 文件夾 -->
    <!-- 根據文件的類型還需要新建相關的文件夾 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>
    <!-- 此參數為是否開啟上傳功能 -->
    <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> <!-- 此參數為文件過濾,以下的文件類型都不可以上傳 -->
    <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>

    新建一個提交頁 jsp1.jsp 文件和一個接收頁 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 三個文件夾。

    ok現在運行一下看看吧!



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

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

    2.建立項目:tomcat/webapps/TestFCKeditor.

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

    4.將FCKeditor-2.3.zip壓縮包中\web\WEB-INF\目錄下的web.xml文件合并到項目的\WEB-INF\目錄下的web.xml文件中。

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

    運行圖:

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

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

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

    9.打開/FCKeditor/fckconfig.js
    修改 FCKConfig.DefaultLanguage = 'zh-cn' ;
    把FCKConfig.LinkBrowserURL等的值替換成以下內容:
    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總配置文件,可用記錄本打開,修改后將文件存為utf-8 編碼格式。找到:

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

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

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

    這也是改過的把鼠標右鍵的“鏈接、圖像,FLASH,圖像按鈕”功能都去掉。

      找到: FCKConfig.FontNames = 'Arial;Comic Sans MS;Courier New;Tahoma;Times New Roman;Verdana' ;
    加上幾種我們常用的字體
    FCKConfig.FontNames
    = '宋體;黑體;隸書;楷體_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>

    <%--
    三種方法調用FCKeditor
    1.FCKeditor自定義標簽 (必須加頭文件 <%@ taglib uri="/TestFCKeditor" prefix="FCK" %> )
    2.script腳本語言調用 (必須引用 腳本文件 <script type="text/javascript" src="/TestFCKeditor/FCKeditor/fckeditor.js"></script> )
    3.FCKeditor API 調用 (必須加頭文件 <%@ 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 發表評論
    ]]>
    祥解WEB應用的部署文件web.xmlhttp://www.aygfsteel.com/xzclog/archive/2006/08/10/62796.htmlxzcxzcThu, 10 Aug 2006 07:10:00 GMThttp://www.aygfsteel.com/xzclog/archive/2006/08/10/62796.htmlhttp://www.aygfsteel.com/xzclog/comments/62796.htmlhttp://www.aygfsteel.com/xzclog/archive/2006/08/10/62796.html#Feedback0http://www.aygfsteel.com/xzclog/comments/commentRss/62796.htmlhttp://www.aygfsteel.com/xzclog/services/trackbacks/62796.html    在分析web.xml文檔之前我想先說一下web.xml中根元素<web-app>各子元素的順序問題,因為在web.xml中元素定義的先后順序是不能顛倒的(除非web.xml文件中使用XML Schema,本文不做討論),否則Tomcat服務器可能拋出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中的開頭幾行是固定的,它定義了該文件的字符編碼,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>內

    <display-name>元素定義這個web應用的名字,Java Web 服務器的Web管理工具將用這個名字來標志Web應用。

    <description>元素用來聲明Web應用的描述信息

    <context-param>元素用來配置外部引用的,在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>
    以上是配置了一個servlet過濾器,對于servlet容器收到的客戶請求以及發出的響應結果,servlet都能檢查和修改其中的信息,以上代碼指名當客戶請求訪問Web應用中的所有JSP文件時,將觸發SampleFilter過濾器工作,具體的過濾事務在由<filter-class>中指定的類來完成

     <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>是實現這個Servlet的類,<init-param>定義Servlet的初始化參數(參數名和參數值),一個Servlet可以有多個<init-param>,在Servlet類中通過getInitParameter(String name)方法訪問初始化參數

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

    <session-config>元素用來設定HttpSession的生命周期,該元素只有一個<session-timeout>屬性,時間單位是“秒”。

    <welcome-file-list>當用戶訪問web時,如果僅僅給出web應用的Root URL,沒有指定具體文件名,容器調用該配置,該元素可以包含多個<welcome-file>屬性。

    <taglib>元素用來設置web引用的tag library,例示定義了一個“/mytaglib”標簽庫,它對應的tld文件為:/WEB_INF/mytaglib.tld
    <taglib>
        <taglib-url>/mytaglib</taglib-url>
        <taglib-locationg>/WEB-INF/mytaglib.tld</taglib-location>
    </taglib>

    <resource-ref>如果web應用由Servlet容器管理的某個JNDI Resource,必須在web.xml中聲明對這個JNDI Resource的引用。
    <resource-ref>
        <description>DB Connection</description> //說明
        <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>用來為Web應用定義安全約束
     <security-constraint>
        <web-resource-collection>//聲明受保護的web資源
           <web-resource-name>ResourceServlet</web-resource-name>//標識受保護web資源
           <url-pattern>/ResourceServlet</url-pattern>//指定受保護的URL路徑
           <http-method>GET</http-method>//指定受保護的方法
           <http-method>POST</http-method>
        </web-resource-collection>
        <auth-constraint>//可以訪問受保護資源的角色
           <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>元素指定當Web客戶訪問受保護資源時,系統彈出的登陸對話框的類型。例示配置了基于表單驗證的登陸界面
    <login-config>
        <auth-method>FORM</auth-method>//BASIC(基本驗證法),DIGEST(摘要驗證),FORM(表單驗證)
        <real-name>設定安全域的名稱</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>指明這個Web應用引用的所有角色名字
    <security-role>
        <description>描述</description>
        <role-name>admin</role-name>
    </security-role>



    xzc 2006-08-10 15:10 發表評論
    ]]>
    主站蜘蛛池模板: 东方市| 宣汉县| 山丹县| 尼木县| 焦作市| 白水县| 新田县| 泸水县| 城口县| 启东市| 于都县| 策勒县| 厦门市| 普兰县| 武清区| 陈巴尔虎旗| 沂源县| 凤阳县| 大冶市| 乳山市| 广德县| 林口县| 新源县| 和林格尔县| 佛学| 乐东| 镇雄县| 大新县| 元阳县| 岳普湖县| 平谷区| 鹤山市| 白山市| 永靖县| 闽清县| 贵州省| 诸暨市| 峡江县| 曲沃县| 天门市| 河西区|