jsp include 乱码问题的解决
jsp include 的文件有时候会出现乱码,经过测试发现如下方法可以修改。
第一种情况可以修改被include的文件:
1.当jsp include动态文件时(jsp文件)可以在被include的jsp文件头部加上代码:
java 代码
- <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
2.当jsp include静态文件时(html文件)可以在被include的html文件的<head></head>标签内加上代码:
xml 代码
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
第二种情况不能够修改被include的文件:
此时可以修改tomcat的web.xml达到目的
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">
-
- <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>UTF-8</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>UTF-8</page-encoding>
- <scripting-invalid>false</scripting-invalid>
- <include-prelude></include-prelude>
- <include-coda></include-coda>
- </jsp-property-group>
- </jsp-config>
-
- </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