怎么加过滤器?
是在当表单提交到ActionForm是就用new String(str.getBytes("Shift_jis"));来重新设置字符集马?这是我都试过的,不行的!
以下是我做的方法,当每次Struts自动将表单内容提交到ActionForm时进行set****()方法是都调用这个方法,可结果还是乱码!
// public String getToString(String str){
// String d=null;
// try {
// d = new String(str.getBytes("Shift-JIS"));
//
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
// return d;
// }
是在当表单提交到ActionForm是就用new String(str.getBytes("Shift_jis"));来重新设置字符集马?这是我都试过的,不行的!
以下是我做的方法,当每次Struts自动将表单内容提交到ActionForm时进行set****()方法是都调用这个方法,可结果还是乱码!
// public String getToString(String str){
// String d=null;
// try {
// d = new String(str.getBytes("Shift-JIS"));
//
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// }
// return d;
// }
已经解决了,我将d = new String(str.getBytes("Shift-JIS"));里的字符集改为iso-8859-1就好了,不过优点困惑,为什么页面的字符集是Shift-JIS而读取时以iso-8859-1字符集进行读取就OK了呢?这些字符集到底是怎么回事啊?谢谢楼上的仁兄
jsp中一般str=new String(str.getBytes("ISO-8859-1"),"GB2312")
我自己写了一个类
在操作数据库的时候调用下就自动把bean类中所有String的编码转换了
呵呵