搞了两个多小时才弄明白为什么我的东西不能正常显示中文,疯了都~~~
刚开始,我试着在XXXaction里面写:
try {
request.setCharacterEncoding("GBK");
System.out.println("字符成功转向");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
System.out.println("字符转向失败!");
}
问题依旧,后来才明白,应该这样做:
1,写一个类,继承RequestProcessor
import java.io.UnsupportedEncodingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.RequestProcessor;
public class EnRequestProcessor extends RequestProcessor {
@Override
protected boolean processPreprocess(HttpServletRequest request,
HttpServletResponse response) {
// TODO Auto-generated method stub
try {
request.setCharacterEncoding("GBK");
System.out.println("字符成功转向");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
System.out.println("字符转向失败!");
}
return true;
}
}
然后,在struts-config.xml里写入:
在</action-mappings>后面加,不要加在里面哦~~
<controller processorClass="com.college.util.EnRequestProcessor"></controller>
好,一切结束!浏览一下看看吧!
爽啊!~~~~