在每个jsp页面中都添加下面如下代码:
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%
request.serCharacterEncoding("GBK");
%>
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %>
<%
request.serCharacterEncoding("GBK");
%>
解决方案 »
- 求员工工资管理系统
- MyEclipse发布SSH框架程序的技巧
- java问题 求解啊
- 200元手机费+200分求序列化例子
- spring+hibernate:Session is closed!
- hibernate的saveOrUpdate方法为什么无法保存或修改数据?
- 如何配置WEBLOGIC7才能运行我的JSP程序,比如说我的JSP程序放在C:\TEST\TEST.JSP?
- jboss中如何部署CMP数据源,数据源是(ORACLE9i),好头疼,走了很多弯路,哪位高手帮忙指点一下
- 这个问题是SQL Server驱动的问题吗???
- springmvc+mybatis+ehcahe配置了单独的ehcache.xml但还是一直使用默认的ehcache-failsafe.xml的配置
- xml解析问题
- JDOM与JDK版本的问题
首先在servlet的相应的方法中添加request.setCharacterEncoding("GBK");
然后取传过来的值:
String name = client.getName();
String clientname = new String(name.getBytes("ISO8859_1"), "gb2312");这样以后,你用out.print()输出的结果应该不会有乱码了。
你说的方法我都用过
我在eclipse里面装个tomcat插件运行的话中文都可以被显示出来
但是直接用tomcat运行的话就会出现我上面说的情况
在server.xml中加入了:
<Connector
port="80" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" URIEncoding="UTF-8" />
才把问题解决了,我的应用用的utf-8的编码,如果我要用GBK,是不是这个配置还要改,真是他妈恶心。
后来又看到更好的一个解决办法,也就是不用这个参数,而是用
useBodyEncodingForURI="true",这样一来,应用无论用什么编码方式,都不需要该tomcat的任何配置了。
下面是这两个参数的说明:
URIEncoding
This specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, ISO-8859-1 will be used.
useBodyEncodingForURI
This specifies if the encoding specified in contentType should be used for URI query parameters, instead of using the URIEncoding. This setting is present for compatibility with Tomcat 4.1.x, where the encoding specified in the contentType, or explicitely set using Request.setCharacterEncoding method was also used for the parameters from the URL. The default value is false.