1 <%@ page contentType="text/html;charset=gb2312"%>
2 <html>
3 <body>
4 我在学习使用include命令
5 </body>
6 </html>上面这个 jsp 程序可以正常运行(即不会乱码):
要是把 2、3、4、5、6 行写成文本文件 test.txt 。然后把程序写成下面的样子,中文部分就会乱码显示。为什么会这样呢? <%@ page contentType="text/html;charset=gb2312"%><%@ include file="test.txt"%>
2 <html>
3 <body>
4 我在学习使用include命令
5 </body>
6 </html>上面这个 jsp 程序可以正常运行(即不会乱码):
要是把 2、3、4、5、6 行写成文本文件 test.txt 。然后把程序写成下面的样子,中文部分就会乱码显示。为什么会这样呢? <%@ page contentType="text/html;charset=gb2312"%><%@ include file="test.txt"%>
2)在你的web.xml里加入如下几行: <filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GB2312</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Set Character Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>3)完成.2 get方式的解决办法
1) 打开tomcat的server.xml文件,找到以下区块,加入如下一行:
URIEncoding=”GB2312”
完整的应如下:<Connector
port="80" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true"
URIEncoding="GB2312"
/>
2)重启tomcat,一切OK。
我按你的方法试过了, 还是不行。
这个问题真的很奇怪。如果把下面语句写成: top.txt
<html>
<body>
我在学习使用include命令再把下面语句写成:bottom.txt
</body>
</html>jsp文件写成这样:
<%@ page contentType="text/html;charset=gb2312"%>
<%@ include file="top.txt"%>
<p align="center">
<%out.println("一个乱码的问题");%>
</p>
<%@ include file="bottom.txt"%>这样的结果是: <%out.println("一个乱码的问题");%> 这一句的文字能正常显示, 其它中文却无法正常显示。