<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    hays

    海納百川
    posts - 25, comments - 48, trackbacks - 0, articles - 0
      BlogJava :: 首頁 ::  :: 聯系 :: 聚合  :: 管理
    解決 <%@ include file="/global/topright.html" %> 的中文亂碼問題 (引用)

    要解決這個問題,當然最簡單的就是在每個被 include 的檔案第一行,加上 <%@ page contentType="text/html;charset=big5" %> 這樣一定可以確保中文 jsp 檔不會出現亂碼,只不過,一旦程式修改成這樣的模式,你的程式就無法在舊的 jsp/servlet container 上執行了,因為舊的規格是不允被 include 檔案中再出現 <%@ page ... %> 這樣的定義的。

    況且,就算你願意為了 Tomcat 5.0.x 特別維護一套不同版本的 Source Code,你會遇到重大的挫折,因為 Tomcat 5.0.x 版在 charset 的設定上,會特別檢查 include 別人的程式與被人 include 的程式,這二個程式中所定義的 charset 是不是一樣,如果不一樣,在編譯時就會產生錯誤。更恐怖的是,竟然還分大小寫,比如說:"big5" "Big5" 這樣的定義,在 Tomcat 的認定上是不同的哦。

    假如有一個 Head.jsp,所有程式都會去 include 的檔案,試著在 Head.jsp 中,加上 <%@ page contentType="text/html;charset=big5" %> ,然後再執行,天啊,有人習慣用 "big5", 有人習慣用 "Big5",更有人習慣用 "BIG5",怎麼辦 ? 難道要一支一支程式去改嗎 ? 還是用 UltraEdit 的 Replace in Files,一次全部更正過來 ? 那日後,是不是得規定所有程式設計師統一採用 "Big5" 呢 ?

    想想,不太可行,也太愚蠢了。

    正確解決方案
    在 Tomcat 5.0.x 中,Tomcat 支援了 JSP 2.0 的規格,同時也支援了部分 J2EE 1.4 的規格,在 J2EE 1.4 的規格中,有關 JSP 的部份,有一個 <jsp-config> 的 XML Tag,這個 XML 區塊用來定義與 JSP 相關的特殊屬性,包含採用的 taglib 與 以下說明的 <jsp-property-group> ,而解決 include 檔中文問題的方法就定義在 <jsp-property-group> 中。

    首先,請至你開發的 webapps 的目錄下,找到 WEB-INF\web.xml 檔案,比如說:eip 專案的目錄,就是 $TOMCAT_HOME\webapps\eip\WEB-INF\web.xml。
    用文字編輯器開啟 web.xml,將以下這段 xml head 的定義 copy & replace 到 web.xml:
    														1
    2
    3
    4
    5
    														<?xml version="1.0" encoding="ISO-8859-1"?> 
    <web-app 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"
    version="2.4">
    
    												

    特別注意,version="2.4",Tomcat 5.0.19 會去偵測這個版本資訊,目前只有 2.4 的才會處理 jsp-config 的參數。
    在 web.xml 中,加上以下這個區塊:
    														1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    														<jsp-config>
    <jsp-property-group>
       <description>
          Special property group for JSP Configuration JSP example.
       </description>
       <display-name>JSPConfiguration</display-name>
       <url-pattern>*.jsp</url-pattern>
       <el-ignored>true</el-ignored>
       <page-encoding>Big5</page-encoding>
       <scripting-invalid>false</scripting-invalid>
       <include-prelude></include-prelude>
       <include-coda></include-coda> 
    ?
       <description>
          Special property group for JSP Configuration JSP example.
       </description>
       <display-name>JSPConfiguration</display-name>
       <url-pattern>*.html</url-pattern>
       <el-ignored>true</el-ignored>
       <page-encoding>Big5</page-encoding>
       <scripting-invalid>false</scripting-invalid>
       <include-prelude></include-prelude>
       <include-coda></include-coda>
    </jsp-property-group>
    </jsp-config>
    
    												

    這二個區塊的定義,就是告知 Tomcat,在 eip 專案目錄下,所有的 .jsp, .html 檔案,若是沒有定義 contentType="text/html;charset=big5" 時,請採用預設的 "Big5" 字元集去處理,如此一來,你就不須要在每個 include 的檔案第一行加上 contentType="text/html;charset=big5" 了。
    想更進一步了解 <jsp-config> 的說明,請參考
    http://java.sun.com/xml/ns/j2ee/#oldresources

    web.xml 範例n
    														1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    														<?xml version="1.0" encoding="ISO-8859-1"?>
    ?
    <web-app 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"
    version="2.4">
    <display-name>EIP 2E PROJECT</display-name>
    <description>EIP 2E PROJECT</description>
    ?
    <jsp-config>
    <jsp-property-group>
       <description>
          Special property group for JSP Configuration JSP example.
       </description>
       <display-name>JSPConfiguration</display-name>
       <url-pattern>*.jsp</url-pattern>
       <el-ignored>true</el-ignored>
       <page-encoding>Big5</page-encoding>
       <scripting-invalid>false</scripting-invalid>
       <include-prelude></include-prelude>
       <include-coda></include-coda>
    ?
       <description>
          Special property group for JSP Configuration JSP example.
       </description>
       <display-name>JSPConfiguration</display-name>
       <url-pattern>*.html</url-pattern>
       <el-ignored>true</el-ignored>
       <page-encoding>Big5</page-encoding>
       <scripting-invalid>false</scripting-invalid>
       <include-prelude></include-prelude>
       <include-coda></include-coda>
    </jsp-property-group>
    </jsp-config>
    ?
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    </welcome-file-list>
    </web-app>
    
    												

    評論

    # re: jsp中的include 亂碼問題解決  回復  更多評論   

    2006-10-14 13:34 by phinecos
    這個能一次性解決問題嗎?

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲综合校园春色| 黄色免费在线网址| 国产成人亚洲综合a∨| 免费国产成人午夜私人影视| 午夜小视频免费观看| 亚洲精品人成网在线播放影院| 成人免费福利视频| a级大片免费观看| 特黄特色的大片观看免费视频| 亚洲AV无码一区东京热| 日韩精品成人亚洲专区| 四虎免费大片aⅴ入口| 四虎在线最新永久免费| 99国产精品免费视频观看| 亚洲国产精品综合久久久| 久久久久亚洲av无码尤物| 亚洲老妈激情一区二区三区| 99re热免费精品视频观看| 无遮挡呻吟娇喘视频免费播放| 香蕉大伊亚洲人在线观看| 91亚洲视频在线观看| 久久久久久亚洲精品成人| 国产av无码专区亚洲av桃花庵| 亚洲一级片免费看| 亚洲国产人成精品| 美女隐私免费视频看| 亚洲AV无码之国产精品| 亚洲heyzo专区无码综合| 亚洲一区精品中文字幕| 亚洲AV日韩AV永久无码久久| 亚洲VA成无码人在线观看天堂| 亚洲女久久久噜噜噜熟女| 中文亚洲AV片在线观看不卡| 毛片在线免费视频| 最近中文字幕mv手机免费高清 | 亚洲人成网77777色在线播放| 国产精品V亚洲精品V日韩精品| 国产亚洲精品自在线观看| 亚洲色大成网站www永久一区| 亚洲日本va中文字幕久久| 亚洲av中文无码乱人伦在线r▽|