搞了好久,调试发现乱码主要出现在formbean中,所以写一个类进行转码就行,呵呵
写一个类进行转码,如
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.RequestProcessor;
import org.apache.struts.config.ForwardConfig;
import org.apache.commons.logging.Log;
public class MyRequestProcessor extends RequestProcessor {
public MyRequestProcessor() {}
protected boolean processPreprocess( HttpServletRequest request,
HttpServletResponse response ){
try{
request.setCharacterEncoding("gb2312"); //按你JSP上设置的字符集定
}
catch(Exception ex){
System.out.println("字符集设置失败");
}
return true;
}
}
然后在struts-config.xml里加上
这样就不会出现乱码了
文章出处:
阅读(708) | 评论(0) | 转发(0) |