Java需要我们学习相当多的知识,下面YJBYS小编为大家整理了关于关于struts的解决方法文章,希望对你有所帮助。
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