交通警察剧情介绍:jsp乱码问题

来源:百度文库 编辑:神马品牌网 时间:2024/05/01 18:59:04
我用的是jdk1.4+Tomcat/5.0.28

代码如下:
request.setCharacterEncoding("gb2312");
String hao1=request.getParameter("hao1");
String hao2=request.getParameter("hao2");
String hao3=request.getParameter("hao3");
String hao5=request.getParameter("hao5");
String hao6=request.getParameter("hao6");
String hao7=request.getParameter("hao7");
String hao8=request.getParameter("hao8");
String hao9=request.getParameter("hao9");
String hao10=request.getParameter("hao10");
String hao11=request.getParameter("hao11");
String hao12=request.getParameter("hao12");
String hao13=request.getParameter("hao13");
String hao14=request.getParameter("hao14");
String hao15=request.getParameter("hao15");
String hao16=request.getParameter("hao16");
String hao17=request.getParameter("hao17");
String hao18=request.getParameter("hao17");
%>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:good","sa","119119");
Statement stmt=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
stmt.executeUpdate("insert into hyzc(nc, yfm, mm, xb, n, y, r, QQ,mail,sj,dq,zy,wt,da,tx,qm,ip) values ('"+hao1+"','"+hao2+"','"+hao3+"','"+hao5+"','"+hao6+"','"+hao7+"','"+hao8+"','"+hao9+"','"+hao10+"','"+hao11+"','"+hao12+"','"+hao13+"','"+hao14+"','"+hao15+"','"+hao16+"','"+hao17+"','"+hao18+"')");
%>

为什么插入到数据库以后,在数据库中显示的是"?"号啊
?谢谢回答!
前面两为的回答都没有解决我的问题,这是什么原因啊!我以前用的tomcat4.3不会有这个问题的
出现错误提示如下:
type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP

An error occurred at line: 401 in the jsp file: /nr/zc.jsp
Generated servlet error:
D:\Tomcat 5.0\work\Catalina\localhost\myjsp\org\apache\jsp\nr\zc_jsp.java:19: cannot resolve symbol
symbol : class UnsupportedEncodingException
location: class org.apache.jsp.nr.zc_jsp
}catch(UnsupportedEncodingException e)
^
1 error

不懂?帮忙啊!

两个地方
第一看你的
<%@ page contentType="text/html;charset=GB2312" %>这个有没有!
第二就是
request.setCharacterEncoding("GBK");
再不行的话换换你的JDBC数据库驱动

这是因为浏览器默认使用UTF-8编码方式来发送请求的,而UTF-8和GB2312编码方式表示字符是不一样的,所以你插到数据库里的是?啊.
以下是我写的一个小函数,可以参考一下,
<%!String zhuan(String str)
{
String result = null;
byte temp[];
try
{
temp=str.getBytes("iso-8859-1");
result=new String(temp);
}catch(UnsupportedEncodingException e)
{
System.out.println(e.toString());
}
return result;
}
%>
把这个小函数加在你的JSP文件里,以后在接受参数的时候可以:
String hao1=zhuan(request.getParameter("hao1"));
这样接受,应该可以把你的问题解决掉的.