package com;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.RequestProcessor;
/*
* 在struts 中处理中文乱码问题,
* 要解决在提交表单时,中文不会出显乱码,
* 只须继承RequestProcessor类,重写processPreprocess这个方法,则可以解决。
* 在strut-config.xml 中 <controller processorClass = "com.MyRequestProcessor"/>
*/
public class MyRequestProcessor extends RequestProcessor{
public MyRequestProcessor(){}
protected boolean processPreprocess(HttpServletRequest request,
HttpServletResponse response){
try{
request.setCharacterEncoding("UTF-8");//在此设置字符集
}
catch(Exception ex){
System.out.println("字符集设置失败");
}
return true;
}
}