<%!
//转码U_to_GB
public String U_to_GB(String s) throws UnsupportedEncodingException
{
String str=s;
str=new String(s.getBytes("GBK"),"ISO8859_1");
return str;
}public String GB_to_U(String s) throws UnsupportedEncodingException
{
String str=s;
str=new String(s.getBytes("ISO8859_1"),"GBK");
return str;
}public String send(String s){
return s;
}
%>
//转码U_to_GB
public String U_to_GB(String s) throws UnsupportedEncodingException
{
String str=s;
str=new String(s.getBytes("GBK"),"ISO8859_1");
return str;
}public String GB_to_U(String s) throws UnsupportedEncodingException
{
String str=s;
str=new String(s.getBytes("ISO8859_1"),"GBK");
return str;
}public String send(String s){
return s;
}
%>
String temps=request.getParameter("pdtname");
temp=temps.getBytes("iso8859-1");
String pdtname=new String(temp);
help!!!!!
之后再转一次:getByte("ISO8859-1","GBK");
问题解决现在还有一个问题,如果掉转来处理,我应该怎么做呢---
我想将一个GBK的中文字段以上面处理过程的相反过程写回去,应该怎么样的顺序呢??
我试过好多都写不成功(写当然成功,但重新读出来则又是乱码啦)----目的是希望写回去之后,我读出来的是正确的,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
不要跟我说:
public String GB_to_U(String s) throws UnsupportedEncodingException
{
String str=s;
str=new String(s.getBytes("ISO8859_1"),"UTF-8");
return str;
}啊。
第一:
在jsp页面加入:
<%@ page contentType="text/html; charset=gb2312" %>
或者在servlet里面
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html; charset=gb2312");
上面的如果在不行就用如下的方法在数据入库前进行调用:
public static String UnicodeToChinese(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}public static String ChineseToUnicode(String s){
try{
if(s==null||s.equals("")) return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}