1, establish a class, including a format to convert Chinese to iso8859-1 encoding method:
publicclass Format2Chinese {
public Format2Chinese() {
}
public String format2IS08859(String str) {
try {
if (str == null str.trim().equals(""))
str = "";
else
str = new String(str.getBytes("ISO8859-1"));
} catch (Exception e) {
e.printStackTrace();
}
return str;
}
}
2, you should add something in your bean, such as the following simple bean:
publicclass Leavemsg
{
public Leavemsg() {
}
//这个要加的,因为写入的时候我们不格式,写出的时候格式化
public Leavemsg(boolean format) {
this.format = format;
}
private String msg;
booleanformat = false; //用于确定是否将字符格式转换
Format2Chinese function = new Format2Chinese();
publicvoid setMsg(String msg) {
if (format) {
this.msg = function.format2IS08859(msg);
} else
this.msg = msg;
}
public String getMsg() {
return msg;
}
}
3, in the use of beans to load data, this statement:
Leavemsg msg=new leavemsg (true); Then all the other operations are the same, OK.
When the page shows the Chinese time will not be a problem, in the JSP page this can be done with this kind of packaging to get content.