如果说就这个要求那么你可以考虑构造一个新的函数:
JSP:(默认你要转换的值是String 名字为 test 如下是转换)
A页面:
<%
test = new String(test.getByte("GB2312"),"UTF-8");
%>
B页面:
<%
test=new String(test.getByte("UTF-8"),"GB2312");
%>
当然B页面的test是从穿过来的数据中读取得。
这里我要说明如果是JSP之间的调用,那么请注意一定要关注穿过来得值,特别是汉字,如果通过IE进行传递,可能会改变其码制。
JSP:(默认你要转换的值是String 名字为 test 如下是转换)
A页面:
<%
test = new String(test.getByte("GB2312"),"UTF-8");
%>
B页面:
<%
test=new String(test.getByte("UTF-8"),"GB2312");
%>
当然B页面的test是从穿过来的数据中读取得。
这里我要说明如果是JSP之间的调用,那么请注意一定要关注穿过来得值,特别是汉字,如果通过IE进行传递,可能会改变其码制。
public static String toGB2312(String s){try{CharToByteConverter toByte=CharToByteConverter.getConverter("GB2312");byte[] orig=toByte.convertAll(s.toCharArray());char[] dest=new char[orig.length];for(int i=0;i; dest[i]=(char)(orig[i] & 0xFF);return new String(dest);}catch(Exception e){System.out.print(e);return s;}}