试试加一个:
public String ex_chinese(String str){
if(str==null){
str ="" ;
}
else{
try {
str = new String(str.getBytes("iso-8859-1"),"gb2312") ;
}
catch (Exception ex) {
}
}
return str ;
}
============jsp调用=======================
例子:
String title=new String(mySmartUpload.getRequest().getParameter("title").getBytes("GBK"),"ISO8859-1");
title = conn.ex_chinese(title);
public String ex_chinese(String str){
if(str==null){
str ="" ;
}
else{
try {
str = new String(str.getBytes("iso-8859-1"),"gb2312") ;
}
catch (Exception ex) {
}
}
return str ;
}
============jsp调用=======================
例子:
String title=new String(mySmartUpload.getRequest().getParameter("title").getBytes("GBK"),"ISO8859-1");
title = conn.ex_chinese(title);
<%@ page contentType="text/html;charset=gb2312" %>bean保存在:
你的jsp文件目录\WEB-INF\classes\没有就自己建目录
public static String AsciiToChineseString(String s)
{
char[] orig =s.toCharArray();byte[] dest =new byte[orig.length];for(int i=0;i<orig.length;i++)dest[i] =(byte)(orig[i]&0xFF);try{
ByteToCharConverter toChar =ByteToCharConverter.getConverter("gb2312");
return new String(toChar.convertAll(dest));}catch(Exception e){}return s;
}
public String replace(String con ,String tag,String rep){
int j=0;
int i=0;
int k=0;
String RETU="";
String temp =con;
int tagc =tag.length();
while(i<con.length()){
if(con.substring(i).startsWith(tag)){
temp =con.substring(j,i)+rep;
RETU+= temp;
i+=tagc;
j=i;
}
else{
i+=1;
}}
RETU +=con.substring(j);
return RETU;
} }
//处理中文问题的自定义函数
<%!
public String getStr(String str)
{
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("GBK");
String temp=new String(temp_t,"ISO8859_1");
return temp;
}
catch(Exception e)
{
e.printStackTrace();
}
return "null";
}
%>
bean文件放在jsp同一下的目录\WEB-INF\classes\
<%String str = new String(request.getParameter("str").getBytes("iso-8859-1"),"GB2312");%>