这个问题有时与JDBC驱动有关,有时与你的页面格式编码有关!请将编码格式改为GBK或UTF8试试!
解决方案 »
- 网上关于JNative处理dll回调函数的例子
- 项目包冲突如何解决?
- 在线等!sorting(‘132554769980’) 传回 ‘012345567899’
- 有个Spring国际资源的配置问题问问各位大侠
- 如何将html文件转换成TIFF(传真文件)
- jsf+EJB3.0开发的系统,当多用户操作时发生数据库锁表问题
- junit如何通过jndi访问datasource的connection
- 请教IncludeAction类的使用
- 很菜很菜的Cannot find ActionMappings or ActionFormBeans collection问题
- 我很想问大家, 程序员的路在哪里?
- Struts的问题
- 关于连接池问题。。。。。
应该就没问题了
String val=new String(request.getParameter("val").getBytes("ISO-8859-1"));
没人知道吗?
pageEncoding="GBK"%>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
呵呵,凑足了三个地方,其他的地方我就不知道了。
还需要指定服务器的编码格式为GBK。如tomcat默认是iso8859-1,而内存是用unicode,这两种编码格式是不兼容的。如果是提交post方式的请求,可以用过滤器。
用下面的函数转就可以了
<%! String trans(String chi)
{
String result = null;
byte temp[];
try
{
temp =chi.getBytes("iso-8859-1");
result = new String(temp);
}
catch(UnsupportedEncodingException e){
System.out.println(e.toString());
}
return result;
}
%>
<%
Out.println(trans(要输出的字符串));
%>
tomcat该编码格式在server.xml里<Connector port="8080" ...... URIEncoding="GBK"/>
String str=new String(str.getBytes("iso-8859-1"),"gb2312");就行了,或者使用过滤器....
用函数进行转就可以了啊
SQL默认是简体中文。
如:<%@ page contentType="text/html; charset=GB2312" language="java"%>
或:<%@ page contentType="text/html; charset=GBK" language="java"%>2、数据库读取中文数据后用个方法进行转换,如下:
public class ToChinese {
public static String toChinese(String strvalue) {
try {
if (strvalue == null) {
return null;
} else {
strvalue = new String(strvalue.getBytes("ISO8859_1"), "GB2312");
return strvalue;
}
} catch (Exception e) {
return null;
}
}
}