方法一:
public static String changeStr(String str){
try {
str = new String(str.getBytes("ISO-8859-1"),"GBK");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return str;
}
方法二:
1.Strut配置文件
<controller processorClass="com.lib.processor.EncodingProcessor" />
2.重写EncodingProcessor
public class EncodingProcessor extends RequestProcessor {
public void process(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gbk");
response.setContentType("text/html;charset=gbk");
super.process(request, response);
}
}