// TODO 目前使用ISO8859-1编码作为输入! 

private String convertEncoding(String requestXML) {

String temp = "";

try {

temp = new String(requestXML.getBytes("ISO8859-1"), "UTF-8");

} catch (UnsupportedEncodingException e) {

Assert.state(false, e.getMessage());

}

return temp;

}



public class ConvertToolUtils {


public static String gbk2iso(String src) {

return convertEncoding(src, "GBK", "ISO-8859-1");

}


public static String iso2gbk(String src) {

return convertEncoding(src, "ISO-8859-1", "GBK");

}


public static String convertEncoding(String source, String sourceEncoding, String targetEncoding) {

try {

if (source == null || source.equals("")) {

return "";

} else {

return new String(source.getBytes(sourceEncoding), targetEncoding);

}

} catch (Exception e) {

return "";

}

}


public static int ConvertStrNum2IntNum(String strNum) {

int Num = 0;

try {

if (null == strNum || strNum.trim().equals("")) {

Num = 0;

} else {

Num = Integer.parseInt(strNum);

}


} catch (Exception e) {

Num = 0;

e.printStackTrace();

}

return Num;

}


}


使用方式:

requestXML = ConvertToolUtils.convertEncoding(requestXML,"ISO8859-1","UTF-8");