public static String encode(String str)
{
try
{
String temp_p = str;
byte temp_t[] = temp_p.getBytes("ISO8859-1");
return new String(temp_t, "GBK");
}
catch(Exception e)
{
return "NULL";
}
} public static String convert2utf8(String str)
{
try
{
byte bytesStr[] = str.getBytes("ISO-8859-1");
return new String(bytesStr, "UTF8");
}
catch(Exception ex)
{
return str;
}
} public static String convert2iso(String str)
{
try
{
byte bytesStr[] = str.getBytes();
return new String(bytesStr, "ISO-8859-1");
}
catch(Exception ex)
{
return str;
}
}
{
try
{
String temp_p = str;
byte temp_t[] = temp_p.getBytes("ISO8859-1");
return new String(temp_t, "GBK");
}
catch(Exception e)
{
return "NULL";
}
} public static String convert2utf8(String str)
{
try
{
byte bytesStr[] = str.getBytes("ISO-8859-1");
return new String(bytesStr, "UTF8");
}
catch(Exception ex)
{
return str;
}
} public static String convert2iso(String str)
{
try
{
byte bytesStr[] = str.getBytes();
return new String(bytesStr, "ISO-8859-1");
}
catch(Exception ex)
{
return str;
}
}
解决方案 »
- Struts2后台处理xheditor图片上传(在线等)
- 救命啊:null为空或不是对象 是什么原因啊?在线等候
- jsp 清理用户输入,比如<td>会破坏页面结构
- log4j.xml无法打印日志
- 请我用JCreate3.0编写JavaBean的时候为什么用它自带的工具总是无法认出JavaBean的属性?!!!!!!!!
- jsp+mysql有时功能不好使
- Ajax
- TomCat下Servlet不刷新,请教原因?
- 远程连接一台redhat 8.0机器中的mysql出现的问题
- jsp中如何得到select count(*) from table1中的记数值
- ===菜鸟提问===请问怎么在jsp页面上生成一个csv文件??
- 急救!
这个问题我也碰到过 要编码转化下 就用3楼的CODE最后
String title=encode(Request.getParameter(title));
{
if ((pstrWord != null) && (!pstrWord.equals("")))
{
pstrWord = new String(pstrWord.getBytes("ISO8859_1"), "GBK");
return pstrWord;
}
return "";
}
public static 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 ;
} public static String toReChinese(String pstrWord) throws java.io.UnsupportedEncodingException
{
if ((pstrWord != null) && (!pstrWord.equals("")))
{
pstrWord = new String(pstrWord.getBytes("GBK"), "ISO8859_1");
return pstrWord;
}
return "";
}
调用这两个方法试试,其中一个肯定行
是不是和坏境有问题呢..我用的是win2000server+JBX+mysql-4.0.23-win JDBC是mysql-connector-java-3.0.16-ga-bin.jar
<"%@ page contentType="text/html;charset=gb2312"%">这样写数据库的时候字符串可以不转换,但是从数据库中读出来的时候如果有中文字符,则一定要先转换一次编码,然后显示。这样就没有问题。
如果不是在JSP页面,其方法也差不多,读出来后要转换,写的时候可以不转换。
另外我不知道你用的是什么GUI工具,可能你那个工具不支持中文。
试试这样!