這樣轉化一下
String str=request.getParameter("txtName");
str=new String(str.getBytes("iso-8859-1"),"GBK");
String str=request.getParameter("txtName");
str=new String(str.getBytes("iso-8859-1"),"GBK");
解决方案 »
- Hibernate保存数据时,自动清除了数据库中所有的记录
- jsp页面显示
- 在struts2 的action里,想用request ,怎么办?
- form中的action属性与struts-config.xml文件中的path如何对应 ?
- struts中同一path有不同的参数如何配置不同struts-config.xml中的action
- 怎么实现大文件上传?
- 请问如何用bean:write定义过滤规则?
- 一个关于javaBean的小问题了(100分)
- jsp中图片存进数据库
- 如何将链接中的值传递给serlvet中的函数
- 请教iplanet的中文乱码问题!急急急!
- jsp新手在线等待:tomcat里javabean的路径问题
解决办法:
第一:
在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;
}
}3:)解决weblogic/webshpere中文问题:
在web.xml文件中需要配置中文环境。r如下:
<context-param>
<param-name>weblogic.httpd.inputCharset./*</param-name>
<param-value>GB2312</param-value>
</context-param>
可是你知道再asp.net相关的函数怎么写吗?
try{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859-1");
String temp=new String(temp_t);
return temp.trim();
}catch(Exception e)
{
return "null";
}
}
这种情况,我总是这么处理的,希望能对你有用
页面是gb2312
页面提交会有一个过程gb2312-》iso-8859-1
所以你要把他转成iso-8859-1——》gb2312
数据库格式是iso-8859-1
所以入数据的时候要gb2312-》iso-8859-1,否则是乱码
从数据里面出来就是8859,所以必须要转化成2132才能显示。转化的方法String sApp = new String(rs.getString(1).getBytes("iso-8859-1"),"gb2312")反之
String sDB = new String(sDB.getBytes("gb2312"),"iso-8859-1")