request取出的中文为乱码,但是另外的页面是正常的(tomcat)!救急了!up分赃
在tomcat的使用中,原来运行的系统是正常,现在新近在系统上加入了一个新的页面,原来系统正常,但是新的页面运行错误。设置页面解码,和设置字符集都使用了
但是还是出现中文乱码现象。
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>
infoaddsave
</title>
</head>
<jsp:useBean id="conn" scope="page" class="netgate.conn" />
<body>
<%
//String sqlsel=new String(),sqlins=new String();
//String mobile= new String(),specode=new String(),msg=new String();
request.setCharacterEncoding("GBK");
String mobile=(String)request.getParameter("mobile");
String specode=(String)request.getParameter("specode");
String msg=(String)request.getParameter("msg");
byte[] bspecode=specode.getBytes("GBK");
specode=new String(bspecode);
byte[] bmobile=mobile.getBytes("GBK");
mobile=new String(bmobile);
byte[] bmsg=msg.getBytes("GBK");
msg=new String(bmsg);
String sqlsel="select SpCode from login where SgCode='"+specode+"'";
out.print(msg);
ResultSet Rs=conn.executeQuery(sqlsel);
if (Rs.next()){
//String SpCode=new String();
String SpCode=Rs.getString("SpCode");
String sqlins="insert into receivewait (SpCode,UserCode,Message,Mobile) VALUES ('"+SpCode+"','"+
specode+"','"+msg+"','"+mobile+"')";
System.out.print(sqlins);
conn.executeInsert(sqlins);
}
conn.destory();
%>
</body>
</html>
但是还是出现中文乱码现象。
<%@ page contentType="text/html; charset=gb2312" %>
<%@ page import="java.sql.*" %>
<html>
<head>
<title>
infoaddsave
</title>
</head>
<jsp:useBean id="conn" scope="page" class="netgate.conn" />
<body>
<%
//String sqlsel=new String(),sqlins=new String();
//String mobile= new String(),specode=new String(),msg=new String();
request.setCharacterEncoding("GBK");
String mobile=(String)request.getParameter("mobile");
String specode=(String)request.getParameter("specode");
String msg=(String)request.getParameter("msg");
byte[] bspecode=specode.getBytes("GBK");
specode=new String(bspecode);
byte[] bmobile=mobile.getBytes("GBK");
mobile=new String(bmobile);
byte[] bmsg=msg.getBytes("GBK");
msg=new String(bmsg);
String sqlsel="select SpCode from login where SgCode='"+specode+"'";
out.print(msg);
ResultSet Rs=conn.executeQuery(sqlsel);
if (Rs.next()){
//String SpCode=new String();
String SpCode=Rs.getString("SpCode");
String sqlins="insert into receivewait (SpCode,UserCode,Message,Mobile) VALUES ('"+SpCode+"','"+
specode+"','"+msg+"','"+mobile+"')";
System.out.print(sqlins);
conn.executeInsert(sqlins);
}
conn.destory();
%>
</body>
</html>
...全文
相关推荐
如何解决Tomcat下中文乱码问题?
现在将常见的乱码问题分为JSP页面显示中文乱码、表单提交乱码两类。 1)JSP页面中显示中文乱码 在JSP文件中使用page命令指定响应结果的MIME类型,如
解决tomcat中文乱码问题
java中解决tomcat中文乱码的文档
解决tomcat下中文乱码问题
解决tomcat下中文乱码问题, 在tomcat_home\conf\server.xml 中的Connector元素中设置URIEncoding属性为合适的字符编码
java request.getParameter中文乱码解决方法
今天跟大家分享几个解决java Web开发中,request.getParameter()获取URL中文参数乱码的解决办法,需要的朋友可以参考下
解决Tomcat中文乱码
解决tomcat中文乱码的问题!!!!!! !!!!!!!!!!!!!!!!!!!


Web 开发
