在tomcat下html亂碼 問題解決

有的時候我們項目要求不用jsp寫的一些頁面出現了中文亂碼。

究其原因

雖然是直接請求的html路徑 ,但是還是會經過服務器端如tomcat來返回該html頁面。

而有的時候服務器的編碼格式你也不好改變。  

在網上找了很多。最後找到在web.xml裏設置這些就可以解決html亂碼問題。

   <jsp-config>
        <jsp-property-group>
            <description>
                Special property group for JSP Configuration JSP example.
            </description>
            <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>UTF-8</page-encoding>
            <scripting-invalid>false</scripting-invalid>
            <include-prelude></include-prelude>
            <include-coda></include-coda>
        </jsp-property-group>
    </jsp-config>

 要記得加載順序。比過濾器先就可以了。 例如在struts配置前面就可以了。


我們項目的web順序是:

spring  -------  log  ------   listener  --------- html encoding ----------- springSecurity   -------   Character encoding  -------  struts  ------------ sitemesh -------- welcome

就這樣。



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章