| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2184 人关注过本帖
标题:传递中文产生乱码!生气呀
只看楼主 加入收藏
fqj793
Rank: 1
等 级:新手上路
威 望:2
帖 子:228
专家分:0
注 册:2006-12-9
收藏
得分:0 

还是不行呀!


知识改变命运!!!
2007-02-06 09:32
every
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2006-7-11
收藏
得分:0 
在接收页面加上request.setCharacter("gb2312")(没写错吧。。)看看行不行。。

花儿为什么这样红??
2007-02-06 12:51
angeloc
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:36
帖 子:1353
专家分:0
注 册:2006-11-21
收藏
得分:0 
以下是引用fqj793在2007-2-6 9:32:23的发言:

还是不行呀!

我看你把两个页面代码贴上来好了,你这么说永远也不知道你到底哪写的有问题


老牛明知夕阳晚,不用扬鞭自奋蹄; Angelo\'s BLOG
2007-02-06 17:36
fqj793
Rank: 1
等 级:新手上路
威 望:2
帖 子:228
专家分:0
注 册:2006-12-9
收藏
得分:0 

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>公司管理系统</title>
<style type="text/css">
<!--
body {
background-image: url(image/bj.gif);
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
.style2 {color: #0033FF}
-->

</style></head>
<body>
<%
request.setCharacterEncoding("gb2312");

request.getSession(true);
String name=new String(request.getParameter("user").getBytes("ISO8859_1"),"GBK");

String password=new String(request.getParameter("pass").getBytes("ISO8859_1"),"GBK");

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String url="jdbc:odbc:mydata";
String username="";
String pass="";
Connection con=DriverManager.getConnection(url,username,pass);
Statement stmt=con.createStatement();
String sql="select * from wglperson where username='"+name+"'and password='"+password+"'";
ResultSet rs=stmt.executeQuery(sql);
if (rs.next())
{
int web=rs.getInt("web");
String personid=rs.getString("username");
session.setAttribute("personid",personid);
if (web==1)
{
%>

<table width="800" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<table width="800" border="0"align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="6"><img src="image/top2.gif" width="800" height="58"></td>
</tr>
<tr>
<td width="165" height="22"><img src="image/nav1.gif" width="165" height="22"></td>
<td colspan="5" bgcolor="#CCCCCC"><img src="image/top2.gif" width="635" height="22"></td>
</tr>
<tr>
<td colspan="6"><img src="image/spl_1.gif" width="76" height="72"><img src="image/top2.gif" width="724" height="72"></td>
</tr>
<tr><td colspan="6"> <h3 align="center" class="style2">欢迎进入管理员界面</h3></td></tr>
<tr>
<td height="340"><img src="image/separator.gif" width="2" height="340"></td>
<td width="95">dfd</td>
<td width="127"><div align="right">dfd</div></td>
<td width="113">dfd</td>
<td width="100">dfd</td>
<td width="200"><div align="right"><img src="image/separator.gif" width="2" height="340"></div></td>
</tr>
<tr>
<td>dfd</td>
<td width="95">dfd</td>
<td width="127">dfd</td>
<td width="113">dfd</td>
<td width="100">dfd</td>
<td width="200">dfd</td>
</tr>
<tr>
<td>dfd</td>
<td width="95">dfd</td>
<td width="127">dfd</td>
<td width="113">dfd</td>
<td width="100">dfd</td>
<td width="200">dfd</td>
</tr>
<tr>
<td colspan="6"><img src="image/top2.gif" width="800" height="58"></td>
</tr>
<%}

if (web==2)
{
%>

</table>

<table width="800" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
<table width="800" border="0"align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="6"><img src="image/top2.gif" width="800" height="58"></td>
</tr>
<tr>
<td width="165" height="22"><img src="image/nav1.gif" width="165" height="22"></td>
<td colspan="5" bgcolor="#CCCCCC"><img src="image/top2.gif" width="635" height="22"></td>
</tr>
<tr>
<td colspan="6"><img src="image/spl_1.gif" width="76" height="72"><img src="image/top2.gif" width="724" height="72"></td>
</tr>
<tr>
<td>

</td>
<td colspan="4"><p align="center"><font size="+3" color="#0033FF" >欢迎光临领导用户界面</font></p></td>
<td width="139">&nbsp;</td>
</tr>
<tr>
<td height="400"><img src="image/separator.gif" width="2" height="400"></td>
<td width="149">&nbsp;</td>
<td width="133"></td>
<td width="156">&nbsp;</td>
<td width="76">&nbsp;</td>
<td width="139"><div align="right"><img src="image/separator.gif" width="2" height="400"></div></td>
</tr>
<tr>
<td colspan="6"><img src="image/top2.gif" width="800" height="58">
<%}

if (web==0)
{
%>

</table>

<table width="800" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td height="599">
<table width="800" border="0"align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="6"><img src="image/top2.gif" width="800" height="58"></td>
</tr>
<tr>
<td width="165" height="22"><img src="image/nav1.gif" width="165" height="22"></td>
<td colspan="5" bgcolor="#CCCCCC"><img src="image/top2.gif" width="635" height="22"></td>
</tr>
<tr>
<td colspan="6"><img src="image/spl_1.gif" width="76" height="72"><img src="image/top2.gif" width="724" height="72"></td>
</tr>
<tr>
<td height="26">

</td>
<td colspan="4"><p align="center"><font size="+3" color="#0033FF" >欢迎光临普通用户界面</font></p></td>
<td width="139">&nbsp;</td>
</tr>
<tr>
<td height="360"><img src="image/separator.gif" width="2" height="360"></td>
<td width="165"><a href="yuangong/rest.jsp"><img src="image/qj.jpg" width="150" height="55" border="0"></a></td>
<td width="117"></td>
<td width="156"><a href="yuangong/restuser.jsp"><img src="image/qjcx.jpg" width="150" height="55" border="0"></a></td>
<td width="76">&nbsp;</td>
<td width="139"><div align="right"><img src="image/separator.gif" width="2" height="360"></div></td>
</tr>
<tr>
<td height="61" colspan="6"><img src="image/top2.gif" width="800" height="58"><% }}

else
{
rs.close();

response.sendRedirect("error.jsp?msg=您好的输入有错误!");


}

%></td>
</tr>

</table>

</td>
</tr>
</table>



</body>
</html>
以下是error.jsp的内容
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>公司内部系统---</title>
<style type="text/css">
<!--
body {
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
background-image: url(image/bj.gif);
}
.style1 {
font-size: 16px;
font-weight: bold;
}
.style2 {
color: #0066FF;
font-weight: bold;
font-size: 18px;
}
-->
</style></head>
<SCRIPT LANGUAGE="JavaScript">
function setf()
{
document.for1.user.focus();
}
function cancle()
{ document.for1.user.value="";
document.for1.pass.value="";
return false;
}
function selec(txt)
{
txt.focus();
txt.select();
}
function chkUser(txt)
{ var user = document.for1.user;
if (user.value=="")
{
alert ("please input username");
selec(txt);
return false;
}else{
return true;}
}
function chkPw(txt)
{ var pw = document.for1.pass;
if (pw.value=="")
{
alert ("please input password");
selec(txt);
return false;
}else{
return true;}
}
function chkUserPw()
{var user = document.for1.user;
var pw = document.for1.pass;
if(chkUser(user))
{
if(chkPw(pw))
{
return true;
}
return false;
}
return false;
}
</SCRIPT>

<body>
<table width="800" border="0"align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="6"><img src="image/top2.gif" width="800" height="58"></td>
</tr>
<tr>
<td width="165" height="22"><img src="image/nav1.gif" width="165" height="22"></td>
<td colspan="5" bgcolor="#CCCCCC"><img src="image/top2.gif" width="635" height="22"></td>
</tr>
<tr>
<td colspan="6"><img src="image/spl_1.gif" width="76" height="72"><img src="image/top2.gif" width="724" height="72"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td width="55">&nbsp;</td>
<td width="301"><div align="center" class="style2">公司内部管理系统</div></td>
<td width="54">&nbsp;</td>
<td width="89">&nbsp;</td>
<td width="136">&nbsp;</td>
</tr>
<tr>
<td height="300"><img src="image/separator.gif" width="2" height="400"></td>
<td>&nbsp;</td>
<td><form action="logo.jsp" name="for1" method="post" onSubmit="return chkUserPw()"><table width="100%" border="0" >
<tr>
<td width="29%">&nbsp;</td>
<td width="31%"><span class="style1">username</span></td>
<td width="29%">&nbsp;</td>
<td width="11%">&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="text" name="user" size="12">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><span class="style1">password</span></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="password" name="pass" size="16">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="center"><input type="image" border="0" name="imageField" src="image/login.gif" width="60" height="25"></td>
<td>&nbsp;</td>
<td><input type="image" border="0" name="imagereset" src="image/reset.gif" width="60" height="25" onClick="return cancle();"></td>
<td>&nbsp;</td>
</tr>
<tr>
<td colspan="3">
<%
request.setCharacterEncoding("gb2312");

String msg=new String(request.getParameter("msg").getBytes("ISO8859_1"),"GBK");
if(msg!=null)
out.print("<br>"+msg);
%>
</td>
<td>&nbsp;</td>
</tr>
</table>
</form></td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><img src="image/separator.gif" width="2" height="400" align="right"></td>
</tr>
<tr>
<td colspan="6"><img src="image/top1.gif" width="800" height="58"></td>
</tr>
</table>
</body>
</html>
红色部分为所述代码!


知识改变命运!!!
2007-02-06 17:55
bagger
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:33
帖 子:891
专家分:0
注 册:2005-8-16
收藏
得分:0 
request.setCharaterEncoding("GBK");
或request.setCharaterEncoding("GB2312");
之后再request
就不会出现中文乱码了

【三元毕业设计论文】
三元论文真的只有三元钱
客服QQ:742670649
http://shop35094218./
2007-02-06 22:40
angeloc
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:36
帖 子:1353
专家分:0
注 册:2006-11-21
收藏
得分:0 
response.sendRedirect("error.jsp?msg=<%=URLEncoder.encode('您好的输入有错误!')%>");
你加上URLEncoder!

老牛明知夕阳晚,不用扬鞭自奋蹄; Angelo\'s BLOG
2007-02-07 08:57
fqj793
Rank: 1
等 级:新手上路
威 望:2
帖 子:228
专家分:0
注 册:2006-12-9
收藏
得分:0 

我在String msg=new String(request.getParameter("msg").getBytes("ISO8859_1"),"GBK");之前有加这句呀,request.setCharaterEncoding("GB2312");


知识改变命运!!!
2007-02-07 10:55
风月_无边
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:60
帖 子:2960
专家分:652
注 册:2007-1-19
收藏
得分:0 

ISO-8859-1 是不是写错了


我的网站 http://www.
2007-02-07 13:36
fqj793
Rank: 1
等 级:新手上路
威 望:2
帖 子:228
专家分:0
注 册:2006-12-9
收藏
得分:0 

这一步我做了!


知识改变命运!!!
2007-02-07 15:32
angeloc
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:36
帖 子:1353
专家分:0
注 册:2006-11-21
收藏
得分:0 
以下是引用fqj793在2007-2-7 10:55:40的发言:

我在String msg=new String(request.getParameter("msg").getBytes("ISO8859_1"),"GBK");之前有加这句呀,request.setCharaterEncoding("GB2312");

我那种方法你试了么?


老牛明知夕阳晚,不用扬鞭自奋蹄; Angelo\'s BLOG
2007-02-07 15:45
快速回复:传递中文产生乱码!生气呀
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.123362 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved