jsp 乱码 怎么解决?
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8"%><%!
String Spname = "请输入商品名称";
String pname1;
//转码代码
String changeString(String str){
try{
byte[]b = str.getBytes("ISO-8859-1");
str = new String(b,"utf-8");
}catch(Exception e){
}
return str;
}
%>
<html>
<body>
<form action="" method="post">
<%
request.setCharacterEncoding("utf-8");
String pname = changeString(request.getParameter("pname"));
pname1 = pname;
System.out.println(pname);
session.setAttribute("Rpname", pname);
Spname = (String) session.getAttribute("Rpname");
if (Spname == null) {
Spname = "请输入商品名称";
}
%>
<center>
您要检索商品为:
<input type="text" name="pname" value="<%=Spname%>" />
<input type="submit" value="检索" />
<br />
<br />
<br />
<%
String url = "jdbc:oracle:thin:@localhost:1521:orcl";
String name = "system";
String paw = "Sa123456";
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
con = DriverManager.getConnection(url, name, paw);
//String sql1 = "select p_image,p_name,p_type,p_price,p_quantity,p_time from shop_product where p_name like '%"+pname+"%'";
String sql = "select p_image,p_name,p_type,p_price,p_quantity,p_time from shop_product where p_name like ?";
ps = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
pname = "%" + pname + "%";
ps.setString(1, pname);
rs = ps.executeQuery();
}
catch (Exception e)
{
System.out.print("异常");
e.printStackTrace();
}
%>
<table border="1" cellpadding="10" cellspacing="0">
<tr>
<th>
商品图片
</th>
<th>
商品类型
</th>
<th>
商品价格
</th>
<th>
商品数量
</th>
<th>
上架日期
</th>
</tr>
<%
String sPage = request.getParameter("page");
if(sPage==null||sPage.equals(""))
{
sPage = "1";
}
int currentPage = Integer.parseInt(sPage.trim());//当前页
int pageSize = 10;//页面显示行数
int maxPage =0;//页面数变量
int recordCount = 0;//总行变量
rs.last();//移到最后一行
recordCount = rs.getRow();//获取总行数
maxPage = (recordCount%pageSize==0)?(recordCount/pageSize):((recordCount/pageSize)+1);//获取页面总数
if(rs.absolute((currentPage-1)*pageSize+1))//指针移动到这一行
{
for(int i=0;i<pageSize;i++)
{
%>
<tr>
<td>
<img src="<%=rs.getString("p_image")%>" width="50" height="50" />
</td>
<td><%=rs.getString("p_name")%></td>
<td><%=rs.getString("p_price")%></td>
<td><%=rs.getInt("p_quantity")%></td>
<td><%=rs.getString("p_time")%></td>
</tr>
<%
if(!rs.next()){break;}
}
}
if(currentPage>1)
{
%>
<a href="index.jsp?pname=<%= pname1%>&page=<%= "1"%>">首页</a>
<a href="index.jsp?pname=<%= pname1%>&page=<%= currentPage-1+""%>">上一页</a>
<%
}
if(currentPage<maxPage)
{
%>
<a href="index.jsp?pname=<%= pname1%>&page=<%= currentPage+1+""%>">下一页</a>
<a href="index.jsp?pname=<%= pname1%>&page=<%= maxPage%>">尾页</a>
<%
}
rs.close();
ps.close();
con.close();
%>
</table>
</center>
</form>
</body>
</html>
这是我写的分页代码 当我汉字查询时 出现“??” 可是我已经转码了 为什么还乱码啊 我有点抓狂 水平没到啊! 求求各位大神能帮帮小弟一把 可能有点浪费您的一点时间 但也许是您的一句话 拯救了我的未来 拜谢 以前都是在百度 可是百度允许的字数太少 没法说清楚 所以就20分 全拿出来了 刚申请的 刚申请的 别嫌少 再次谢谢