html tomcat上亂碼

來源:互聯網
上載者:User

今天一個做美工的同事往伺服器上發布html頁面時顯示亂碼,改成htm後正常,網上有一個解決辦法

如下:

tomcat4.X 中的html顯示為亂碼!為什嗎?

  • -----------------------------------------------------------------------------------------我的tomcat4.1.29中的載入html檔案靜態檔案會有亂碼!    
    而顯示jsp不會有亂碼,請用怎麼解決?    要配置什麼tomcat的xml檔案嗎?  
     
    我現在知道一個解決方案是把index.html檔案用記事本開啟然後另存新檔UTF-8格式後就不會亂碼了。可是這隻能治標不治本啊!誰有完全解決方案?  謝謝!  
    =========================================================================  
    加入配置:  
    <mime-mapping>  
                   <extension>htm</extension>  
                   <mime-type>text/html;charset=gb2312</mime-type>  
           </mime-mapping>  
    <mime-mapping>  
                   <extension>html</extension>  
                   <mime-type>text/html;charset=gb2312</mime-type>  
    </mime-mapping>  
     
    謝謝,使用以上方法解決了!!!  
     
    解決方案是,修改tomcat程式目錄下的  /webapps/web_inf/web.xml  檔案,    
     
    添加一段配置代碼:  
     
    <mime-mapping>  
                   <extension>htm</extension>  
                   <mime-type>text/html;charset=gb2312</mime-type>  
           </mime-mapping>  
    <mime-mapping>  
                   <extension>html</extension>  
                   <mime-type>text/html;charset=gb2312</mime-type>  
    </mime-mapping>  
     
    即可解決tomcat中瀏覽html亂碼問題!  
     
    如果想解決所有tomcat所有工程亂碼,則應修改  tomcat目錄下  /conf/web.xml  檔案即可。  
     
    謝謝!!!!  
     
     
    ---------------------------------------------------------------  
    還有一種解決方案是將tomcat和Apache結合一下就行了,讓Apache解釋html,讓tomcat解釋jsp等檔案。然後修改只需修改Apache配置就行了。  
    在Apache的conf檔案夾下,httpd.conf,裡面有AddDefaultCharset  ISO-8859-1,你把它改成  AddDefaultCharset  GB2312。
  • -------------------------------------------------------------------------------------------------------------------------------------------------------

    公司web.xml檔案內容如下

    <?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">
    <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>GBK</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>GBK</page-encoding>
       <scripting-invalid>false</scripting-invalid>
       <include-prelude></include-prelude>
       <include-coda></include-coda>
    </jsp-property-group>
    </jsp-config>

       <filter>
            <filter-name>Set Character Encoding</filter-name>
            <filter-class>filters.SetCharacterEncodingFilter</filter-class>
            <init-param>
                <param-name>encoding</param-name>
                <param-value>GBK</param-value>
            </init-param>
        </filter>
            <filter-mapping>
            <filter-name>Set Character Encoding</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    </web-app>
     

     

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.