这个过滤器有错误吗? 1.demo01.jsp和demo02.jsp编码必须都是GBK2.换成UTF-8 看看3.写的没问题,可能和开发软件版本有关 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 demo01.jsp中加上<%@ page pageEncoding="GBK"%> 如果是Form提交的话:--------------------------------------------public void doFilter(ServletRequest request, ServletResponse response, FilterChain chan) throws IOException, ServletException { response.setContentType("text/html;charset=" + this.encoding); //获取提交的发式是Post还是Get String method = ((HttpServletRequest)request).getMethod(); if(method.equalsIgnoreCase("post")) { request.setCharacterEncoding(this.encoding); } else { Enumeration<String> enu = request.getParameterNames();//获取所有的参数的名称,是一个枚举 while(enu.hasMoreElements()) { String name = enu.nextElement(); String[] value = request.getParameterValues(name); //根据参数名称获取值,是一个字符串数组 for(int i=0;i<value.length;i++) { value[i] = toUTF8(value[i]); } } } chan.doFilter(request, response); } public String toUTF8(String inStr) throws UnsupportedEncodingException { String outStr = ""; if(inStr != null) { outStr = new String(inStr.getBytes("iso-8859-1"),"utf-8"); } return outStr; } 楼上的,这个地方我觉得有问题. else { Enumeration<String> enu = request.getParameterNames();//获取所有的参数的名称,是一个枚举 while(enu.hasMoreElements()) { String name = enu.nextElement(); String[] value = request.getParameterValues(name); //根据参数名称获取值,是一个字符串数组 for(int i=0;i<value.length;i++) { value[i] = toUTF8(value[i]); } } }请求的参数值是重新编码了,但是对request对象没有效果吧?好象是在重编码request的参数值拷贝. TangAlex,你的可以用,但是还是有点不明白你的思路是把所有request对象里面的参数值提取出来进行重编码,对吗?但是我觉得String[] value=request.getParameterValues(name);只是把提取出来的值进行重编码,不会影响到request对象里面的参数啊.是不是我理解错了? fileOutputstream.write(byte[])写入后的内容,比原文件多 怎么用程序获取google地图数据 hibernate问题 在MyEclipse中配置JBoss,启动报错 目前什么免费杀毒软件最好用 这个hibernate查询语句怎么写? activemq的配置问题 Hibernate连接查询的问题,困惑我许久了! struts问题:如何在首页面上实现动态信息? EJB的事务 大家做的项目之中,有在项目中用过EL式的么? 你好,高手,怎么连接jsp??
--------------------------------------------
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chan) throws IOException, ServletException
{
response.setContentType("text/html;charset=" + this.encoding);
//获取提交的发式是Post还是Get
String method = ((HttpServletRequest)request).getMethod();
if(method.equalsIgnoreCase("post"))
{
request.setCharacterEncoding(this.encoding);
}
else
{
Enumeration<String> enu = request.getParameterNames();//获取所有的参数的名称,是一个枚举
while(enu.hasMoreElements())
{
String name = enu.nextElement();
String[] value = request.getParameterValues(name); //根据参数名称获取值,是一个字符串数组
for(int i=0;i<value.length;i++)
{
value[i] = toUTF8(value[i]);
}
}
}
chan.doFilter(request, response);
}
{
String outStr = "";
if(inStr != null)
{
outStr = new String(inStr.getBytes("iso-8859-1"),"utf-8");
}
return outStr;
}
else
{
Enumeration<String> enu = request.getParameterNames();//获取所有的参数的名称,是一个枚举
while(enu.hasMoreElements())
{
String name = enu.nextElement();
String[] value = request.getParameterValues(name); //根据参数名称获取值,是一个字符串数组
for(int i=0;i<value.length;i++)
{
value[i] = toUTF8(value[i]);
}
}
}
请求的参数值是重新编码了,但是对request对象没有效果吧?好象是在重编码request的参数值拷贝.