struts工程form表单提交乱码问题 谢谢了用了 几种方法都不行啊
public class MyRequestProcessor extends RequestProcessor{
public MyRequestProcessor(){}
protected boolean processPreprocess(HttpServletRequest request,
HttpServletResponse response){
try{
request.setCharacterEncoding( "GBK ");//在此设置字符集
}
catch(Exception ex){
System.out.println( "字符集设置失败 ");
}
return true;
}
}
在struts-config.xml中
<controller processorClass= "com.ccu.bbs.requestprocessor.MyRequestProcessor " />
就是不好用 是什么原因呢?
------解决方案--------------------package app;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.RequestProcessor;
public class MyRequestProcessor extends RequestProcessor
{
public MyRequestProcessor() {}
protected boolean processPreprocess(HttpServletRequest request,HttpServletResponse response)
{
try
{
request.setCharacterEncoding( "gb2312 ");
}catch (Exception ex)
{
ex.printStackTrace();
}
return true;
}
}
改成gb2312
------解决方案--------------------用过滤器吧
------解决方案--------------------应改没有问题的。。。
你重新启动一下在看看
------解决方案--------------------用这个方法吧:
public String getStr(String str)
{
try
{
byte[] bt = str.getBytes( "ISO8859-1 ");
String temp = new String(bt);
}catch(Exception e)
{
}
return temp;
}
------解决方案-------------------- 解决页面上的中文显示或者Form提交会乱码的问题,在web.xml加入字符集过滤,如下:
<filter>
<filter-name> charsetFilter </filter-name>
<filter-class> com.company.filter.CharsetFilter </filter-class>
<init-param>
<param-name> charsetEncodingType </param-name>
<param-value> gb2312 </param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name> charsetFilter </filter-name>
<url-pattern> /* </url-pattern>
</filter-mapping>
对应的com.company.filter.CharsetFilter类如下:
package com.company.filter;
import
java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import
javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.apache.commons.lang.StringUtils;
public class CharsetFilter implements Filter{
private static final String characterEncodingType= "charsetEncodingType ";
private static final String defaultCharsetEncode= "gb2312 ";
private String charsetEncode=null;
public void init(FilterConfig arg0) throws
ServletExceptio