求URI 中文乱码解决方案

悬赏:5 发布时间:2008-07-09 提问人:congpeixue (初级程序员)

求URI 中文乱码解决方案

采纳的答案

2008-07-09 ham (资深程序员)

楼主是说的URL传递中文时的乱码吗?

一般遇到的乱码问题可以通过下面的方式来解决:
引用

1.确定JSP页面头部是否有:
<%@ page contentType="text/html; charset=GBK" %>


2.用这个转码:
String param= new String(request.getParameter("param").getBytes("ISO-8859-1"), "GBK");

3.添加filter字符过滤器

4.如果是通过"a.jsp?param=中文"传递参数,则需要:
a.在传参数之前先把参数进行转码:java.net.URLEncoder.encode(param);
取值时用java.net.URLDncoder.decode(param);再转回中文

b.在你的Tomcat目录-->conf目录-->server.xml里找出这段:
<Connector
port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
debug="0" connectionTimeout="20000"
disableUploadTimeout="true" <!--在里边加上这个参数-->URIEncoding="gb2312"
/>


Ps:引用部分由Google而来

提问者对于答案的评价:
問題我已經解決了
辛苦了

部署到tomcat后没问题,才明白是Europa在作怪, Europe保存了tomcat的初次设置

其他回答

很多人问过的问题,看一下这个
引用
congjl2002 (资深程序员) 2008-07-09
web.xml 里加上
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
yangjianxiang2 (初级程序员) 2008-07-09
看看这篇文章:
http://wxy32.javaeye.com/admin/blogs/210703
wxy32 (初级程序员) 2008-07-09