方法一:
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);
}
}
本文介绍两种处理GBK编码的方法。一种是通过Java代码直接转换字符串编码,另一种是在Struts框架中通过配置文件及自定义处理器来统一设置请求和响应的字符集。
299

被折叠的 条评论
为什么被折叠?



