继承RequestProcessor重写process方法:
package com.xj.struts.common;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.RequestProcessor;
public class EncodingProcessor extends RequestProcessor {
public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// TODO Auto-generated method stub
//<controller processorClass="com.xj.struts.common.EncodingProcessor" />
request.setCharacterEncoding("GB2312");
response.setContentType("text/html;charset=GB2312");
super.process(request, response);
}
}
然后在STRUTS配置文件中:
<controller processorClass="com.xj.struts.common.EncodingProcessor" />
把控制器的RequestProcessor默认处理类替换成com.xj.struts.common.EncodingProcessor。