当前位置: 代码迷 >> JavaScript >> jsp include 乱码有关问题的解决
  详细解决方案

jsp include 乱码有关问题的解决

热度:125   发布时间:2012-12-20 09:53:21.0
jsp include 乱码问题的解决

jsp include 乱码问题的解决
jsp include 的文件有时候会出现乱码,经过测试发现如下方法可以修改。
第一种情况可以修改被include的文件:
1.当jsp include动态文件时(jsp文件)可以在被include的jsp文件头部加上代码:

java 代码
  1. <%@?page?language= "java" ?contentType= "text/html;?charset=UTF-8" ??pageEncoding= "UTF-8" %>??

2.当jsp include静态文件时(html文件)可以在被include的html文件的<head></head>标签内加上代码:

xml 代码
  1. < meta ? http-equiv = "Content-Type" ? content = "text/html;?charset=UTF-8" ? /> ??

第二种情况不能够修改被include的文件:
此时可以修改tomcat的web.xml达到目的

xml 代码
  1. <? xml ? version = "1.0" ? encoding = "UTF-8" ?> ??
  2. < web-app ? version = "2.4" ? xmlns = "http://java.sun.com/xml/ns/j2ee" ??
  3. ???? xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance" ??
  4. ???? xsi:schemaLocation ="http://java.sun.com/xml/ns/j2ee ??
  5. ????http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" > ??
  6. ??
  7. ???? < jsp-config > ??
  8. ???????? < jsp-property-group > ??
  9. ???????????? < description > ??
  10. ????????????????Special?property?group?for?JSP?Configuration?JSP ??
  11. ????????????????example. ??
  12. ???????????? </ description > ??
  13. ???????????? < display-name > JSPConfiguration </ display-name > ??
  14. ???????????? < url-pattern > *.jsp </ url-pattern > ??
  15. ???????????? < el-ignored > true </ el-ignored > ??
  16. ???????????? < page-encoding > UTF-8 </ page-encoding > ??
  17. ???????????? < scripting-invalid > false </ scripting-invalid > ??
  18. ???????????? < include-prelude > </ include-prelude > ??
  19. ???????????? < include-coda > </ include-coda > ??
  20. ??
  21. ???????????? < description > ??
  22. ????????????????Special?property?group?for?JSP?Configuration?JSP ??
  23. ????????????????example. ??
  24. ???????????? </ description > ??
  25. ???????????? < display-name > JSPConfiguration </ display-name > ??
  26. ???????????? < url-pattern > *.html </ url-pattern > ??
  27. ???????????? < el-ignored > true </ el-ignored > ??
  28. ???????????? < page-encoding > UTF-8 </ page-encoding > ??
  29. ???????????? < scripting-invalid > false </ scripting-invalid > ??
  30. ???????????? < include-prelude > </ include-prelude > ??
  31. ???????????? < include-coda > </ include-coda > ??
  32. ???????? </ jsp-property-group > ??
  33. ???? </ jsp-config > ??
  34. ??
  35. </ web-app > ??

其中 jsp-config一段是用来说明你要将包含的页面默认按照什么编码格式包含。 web-app 标签的version必须是2.4的。
具体可以参见
http://www.javaworld.com.tw/jute/post/view?bid=9&id=44041&sty=1&tpg=1&age=-1

  相关解决方案