JSP页面使用超链接传递中文参数怎么解决乱码问题

我已经配置了Filter过滤器,用表单提交中文参数没有问题,可以正常显示。但是使用超链接传递中文参数,结果显示是乱码。并且我的IE6已经设置为总是使用UTF8传递参数了。
代码如下:
1.过滤器Java代码
package servlet;

import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public final class CharacterEncodingFilter implements Filter
{

private String encoding;
private boolean ignore;

public CharacterEncodingFilter()
{
encoding = "utf-8";
ignore = false;
}

public void init(FilterConfig config)
{
if (config.getInitParameter("encoding") != null)
encoding = config.getInitParameter("encoding");
if (config.getInitParameter("ignore") != null)
ignore = (new Boolean(config.getInitParameter("ignore"))).booleanValue();
}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException
{
HttpServletRequest req = (HttpServletRequest) request;
HttpServletResponse res = (HttpServletResponse) response;
if (!ignore)
{
req.setCharacterEncoding(encoding);
res.setCharacterEncoding(encoding);
}
chain.doFilter(request, response);
}

public void destroy()
{
}

}
2.web.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<filter>
<filter-name>setEncoding</filter-name>
<filter-class>servlet.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>setEncoding</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>setEncoding</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>setEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>setEncoding</filter-name>
<url-pattern>*.*</url-pattern>
</filter-mapping>

</web-app>

第1个回答  2012-03-22
String pl=req...;
pl = new String(pl.getBytes("iso8859-1"),"GBK");追问

请看清或运行我的代码后再回答,您的这个做法无效。此问题我已解决,在CSDN上已有人解决了我的问题。
谢谢捧场。

第2个回答  2012-03-22
<%@ page contentType="text/html; charset=UTF-8" %>追问

请看清或运行我的代码后再回答,您的这个做法无效。此问题我已解决,在CSDN上已有人解决了我的问题。
谢谢捧场。

相似回答