在页面上显示的从数据库读出的中文都是乱码,试过蛮多方法了,请教!
<%@ page contentType="text/html; charset=gb2312" %>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%@ page import="java.util.*" %>
<%@ page import="bookshop.book.bookclass" %>
<%@ page session="true" %>
<%@ page import="bookshop.book.book"%>
<jsp:useBean id="book" scope="page" class="bookshop.book.book" />
<jsp:useBean id="book_list" scope="page" class="bookshop.run.op_book" />
<jsp:useBean id="classlist" scope="page" class="bookshop.run.op_bookclass" /><%
int pages=1;
String mesg = "";
if (request.getParameter("page")!=null && !request.getParameter("page").equals("")) {
String requestpage = request.getParameter("page");
try {
pages = Integer.parseInt(requestpage);
} catch(Exception e) {
mesg = "你要找的页码错误!";
}
book_list.setPage(pages);
}
%>
<script language="javascript">
function openScript(url,name, width, height){
var Win = window.open(url,name,'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=yes' );
}
</script>
<%@include file="/bookshop/inc/head.inc"%>
<%@include file="/bookshop/inc/sub.inc"%>
<table width="778">
<tr>
<td width="150" align="center">
<%@include file="/bookshop/inc/left.inc"%>
</td>
<td width="600">
<p align="center"><b><font color="#0000FF">清风电子书店图书<%= classname %>列表</font></b></p>
<%if (!keyword.equals("")) out.println("<p ><font color=#ff0000>你要查找关于 " + keyword + " 的图书如下</font></p>"); %>
<table width="100%" border="1" cellspacing="1" cellpadding="1" bordercolor="white">
<tr align="center" bgcolor="#DEF3CE">
<td>图书名称</td>
<td>作者</td>
<td>图书类别</td>
<td>出版社</td>
<td>单价</td>
<td width=110>选择</td>
</tr>
<% if (book_list.book_search(request)) {
if (book_list.getBooklist().size()>0 ){
for (int i=0;i<book_list.getBooklist().size();i++){
book bk = (book) book_list.getBooklist().elementAt(i);%>
<tr>
<td><%= bk.getBookName() %></td>
<td align="center"><%= bk.getAuthor()%></td>
<td align="center"><%= bk.getClassname() %></td>
<td align="center"><%= bk.getPublish() %></td>
<td align="center"><%= bk.getPrince() %>元</td>
<td align="center"><a href="#" onclick="openScript('buy.jsp?bookid=<%= bk.getId() %>','pur',300,250)" >购买</a>
<a href="#" onclick="openScript('detail.jsp?bookid=<%= bk.getId() %>','show',400,500)" >详细资料</a></td>
</tr>
<% }
}else {
if (keyword.equals("")){
out.println("<tr><td align='center' colspan=6> 暂时没有此类图书资料</td></tr>");
} else {
out.println("<tr><td align='center' colspan=6> 没有你要查找的 " + keyword + " 相关图书</td></tr>") ;
}
}
} else {%>
<tr>
<td align="center" colspan=6> 数据库出错,请稍后</td>
</tr>
<% } %> </table>
<table width="90%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td align="right">总计结果为<%= book_list.getRecordCount() %>条,当前页第<%= book_list.getPage() %>页 <a href="booklist.jsp?classid=<%= classid%>&keyword=<%= keyword %>">首页</a>
<% if (book_list.getPage()>1) {%>
<a href="booklist.jsp?page=<%= book_list.getPage()-1 %>&classid=<%= classid%>&keyword=<%= keyword %>">上一页</a>
<% } %>
<% if (book_list.getPage()<book_list.getPageCount()-1) {%>
<a href="booklist.jsp?page=<%= book_list.getPage()+1 %>&classid=<%= classid%>&keyword=<%= keyword %>">下一页</a>
<% } %>
<a href="booklist.jsp?page=<%= book_list.getPageCount() %>&classid=<%= classid%>&keyword=<%= keyword %>">未页</a> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<%@include file="/bookshop/inc/tail.inc"%>
<%@ page contentType="text/html; charset=gb2312" %>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<%@ page import="java.util.*" %>
<%@ page import="bookshop.book.bookclass" %>
<%@ page session="true" %>
<%@ page import="bookshop.book.book"%>
<jsp:useBean id="book" scope="page" class="bookshop.book.book" />
<jsp:useBean id="book_list" scope="page" class="bookshop.run.op_book" />
<jsp:useBean id="classlist" scope="page" class="bookshop.run.op_bookclass" /><%
int pages=1;
String mesg = "";
if (request.getParameter("page")!=null && !request.getParameter("page").equals("")) {
String requestpage = request.getParameter("page");
try {
pages = Integer.parseInt(requestpage);
} catch(Exception e) {
mesg = "你要找的页码错误!";
}
book_list.setPage(pages);
}
%>
<script language="javascript">
function openScript(url,name, width, height){
var Win = window.open(url,name,'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=yes' );
}
</script>
<%@include file="/bookshop/inc/head.inc"%>
<%@include file="/bookshop/inc/sub.inc"%>
<table width="778">
<tr>
<td width="150" align="center">
<%@include file="/bookshop/inc/left.inc"%>
</td>
<td width="600">
<p align="center"><b><font color="#0000FF">清风电子书店图书<%= classname %>列表</font></b></p>
<%if (!keyword.equals("")) out.println("<p ><font color=#ff0000>你要查找关于 " + keyword + " 的图书如下</font></p>"); %>
<table width="100%" border="1" cellspacing="1" cellpadding="1" bordercolor="white">
<tr align="center" bgcolor="#DEF3CE">
<td>图书名称</td>
<td>作者</td>
<td>图书类别</td>
<td>出版社</td>
<td>单价</td>
<td width=110>选择</td>
</tr>
<% if (book_list.book_search(request)) {
if (book_list.getBooklist().size()>0 ){
for (int i=0;i<book_list.getBooklist().size();i++){
book bk = (book) book_list.getBooklist().elementAt(i);%>
<tr>
<td><%= bk.getBookName() %></td>
<td align="center"><%= bk.getAuthor()%></td>
<td align="center"><%= bk.getClassname() %></td>
<td align="center"><%= bk.getPublish() %></td>
<td align="center"><%= bk.getPrince() %>元</td>
<td align="center"><a href="#" onclick="openScript('buy.jsp?bookid=<%= bk.getId() %>','pur',300,250)" >购买</a>
<a href="#" onclick="openScript('detail.jsp?bookid=<%= bk.getId() %>','show',400,500)" >详细资料</a></td>
</tr>
<% }
}else {
if (keyword.equals("")){
out.println("<tr><td align='center' colspan=6> 暂时没有此类图书资料</td></tr>");
} else {
out.println("<tr><td align='center' colspan=6> 没有你要查找的 " + keyword + " 相关图书</td></tr>") ;
}
}
} else {%>
<tr>
<td align="center" colspan=6> 数据库出错,请稍后</td>
</tr>
<% } %> </table>
<table width="90%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td align="right">总计结果为<%= book_list.getRecordCount() %>条,当前页第<%= book_list.getPage() %>页 <a href="booklist.jsp?classid=<%= classid%>&keyword=<%= keyword %>">首页</a>
<% if (book_list.getPage()>1) {%>
<a href="booklist.jsp?page=<%= book_list.getPage()-1 %>&classid=<%= classid%>&keyword=<%= keyword %>">上一页</a>
<% } %>
<% if (book_list.getPage()<book_list.getPageCount()-1) {%>
<a href="booklist.jsp?page=<%= book_list.getPage()+1 %>&classid=<%= classid%>&keyword=<%= keyword %>">下一页</a>
<% } %>
<a href="booklist.jsp?page=<%= book_list.getPageCount() %>&classid=<%= classid%>&keyword=<%= keyword %>">未页</a> </td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
<%@include file="/bookshop/inc/tail.inc"%>
解决方案 »
- 启动报错java.lang.reflect.invocationtargetException
- 问题已解决jasper运行报表时报错(分享): JRBaseElement.backcolor of type java.awt.Color
- java类中获得jsp的路径
- 100分求sqlserver200中text类型,用hibernate解决
- jsp在LINUX下tomcat4.13有时老是出现白屏现像,请问是什么原因,如何解决?
- 大家帮我看看这个用JavaBean连接数据库的程序出错在什么地方!!!!在线急等!!!!!!!!
- 汉字乱码问题,解决就给分!
- 请教关于用hibernate如何表示person和relation两表的关系,细节见贴
- 本论坛左边的动态下拉树型列表用JSP该如何实现呢?
- 我用SQLServer JDBC Driver出现如下错误,但用JDBC-ODBC能成功!急!急!急!
- Tomcat 下,我在我的应用的 web.xml 配置了数据源如下,然后访问代码怎么写?
- 不知道是什么错误了,高手帮忙看看!
http://community.csdn.net/Expert/topic/4757/4757694.xml?temp=.5476038
例如:
String str=request.getParameter();
byte b[]=str.getByte("ISO-9810");
String aa=new String(b);
具体那个参数(ISO-9810)记不清楚了
byte b[]=str.getByte("ISO8859-1");
String aa=new String(b);
<%request.setCharacterEncoding("GBK");%>str = new String(str.getBytes("ISO-8859-1"),"GBK");保证可以!
<%request.setCharacterEncoding("gbk")%>
就OK了
照楼上说的做了出现一下错误?
Generated servlet error:C:\Tomcat\work\Catalina\localhost\_\org\apache\jsp\bookshop\booklist_jsp.java:89: cannot resolve symbol
symbol : method setCharacterEncoding (java.lang.String)
location: interface javax.servlet.http.HttpServletRequest
request.setCharacterEncoding("GBK");
^
1 error
request.setCharacterEncoding("gb2312");在往页面传值时,如果页面上显示是乱码,就把那些可能是中文的字符串加上这么一句:
strName=new String(strName.getBytes("GB2312"),"iso8859-1");
在jsp页面上能改吗?我加这句代码的时候还是会有错,请问怎么改呢?
request.setCharacterEncoding("GBK");
^
1 error