大家好,小弟做的个jsp+javaBena的留言本,提交留言成功,但是提交的留言到数据库中出现乱码啊,杂子整呢?
下面是源码 <%
String str_UserID=session.getAttribute("UserID").toString();
words.setUserID(Integer.parseInt(str_UserID));
String WordsTitle=request.getParameter("WordsTitle");
//编码转换
WordsTitle=new String(WordsTitle.getBytes("iso-8859-1"));
words.setWordsTitle(WordsTitle);
String WordsContent=request.getParameter("WordsContent");
//编码转换
WordsContent=new String(WordsContent.getBytes("iso-8859-1"));
words.setWordsContent(WordsContent);
if(words.add_words()){
out.println("<h2 align=center>留言保存成功</h2>");
}else{
%>
<h2 align="center">留言保存失败</h2>
<center>
<input type="button" name="goback" value="返回" onclick="javascript:window:history.go(-1)">
</center>
<%
}
%>
主要是处理留言标题和留言内容啊,
下面是源码 <%
String str_UserID=session.getAttribute("UserID").toString();
words.setUserID(Integer.parseInt(str_UserID));
String WordsTitle=request.getParameter("WordsTitle");
//编码转换
WordsTitle=new String(WordsTitle.getBytes("iso-8859-1"));
words.setWordsTitle(WordsTitle);
String WordsContent=request.getParameter("WordsContent");
//编码转换
WordsContent=new String(WordsContent.getBytes("iso-8859-1"));
words.setWordsContent(WordsContent);
if(words.add_words()){
out.println("<h2 align=center>留言保存成功</h2>");
}else{
%>
<h2 align="center">留言保存失败</h2>
<center>
<input type="button" name="goback" value="返回" onclick="javascript:window:history.go(-1)">
</center>
<%
}
%>
主要是处理留言标题和留言内容啊,
楼主【qunqun886】截止到2008-08-03 16:23:30的历史汇总数据(不包括此帖):
发帖的总数量:15 发帖的总分数:210 每贴平均分数:14
回帖的总数量:8 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:13 结贴的总分数:180
无满意结贴数:3 无满意结贴分:50
未结的帖子数:2 未结的总分数:30
结贴的百分比:86.67 % 结分的百分比:85.71 %
无满意结贴率:23.08 % 无满意结分率:27.78 %
楼主加油
取消马甲机器人,请点这里:http://www.java2000.net/mycsdn/robotStop.jsp?usern=qunqun886
default-character-set=gbk 让你写的编码和数据库统一起来。
只要编码统一应该就行。
往里insert的时候,转码,转成你数据库使用的编码格式,
WordsTitle=new String(WordsTitle.getBytes("iso-8859-1"),"UTF-8"); WordsContent=new String(WordsContent.getBytes("iso-8859-1),"UTF-8");