怪哉怪哉——路过的大神请进

用displaytag做分页的时候前台:

<%@ page language="java" contentType="text/html; charset=GBK" %>
<%@ taglib prefix="display" uri="http://displaytag.sf.net" %>

<form action="GoodsListServlet" method="post" name="goodsListForm">
商品类型:
<select name="goodsType">
    <option value="母婴用品">母婴用品</option>
    <option value="家具用品">家具用品</option>
    <option value="健康用品">健康用品</option>
    <option value="化妆用品">化妆用品</option>
    <option value="服装服饰">服装服饰</option>
    <option value="手机数码">手机数码</option>
    <option value="动漫周边">动漫周边</option>
</select>
&nbsp;&nbsp;
<input name="" type="submit" value="查询" />
<input type="hidden" name="selectID" value="${sessionScope.goodsType }">
    </form>
</center>
<center>
    <display:table  name="${sessionScope.goodsList}" id="goods" pagesize="6">
<display:column property="goodsID" title="商品编号"></display:column>
<display:column property="goodsName" title="商品名称"></display:column>
<display:column property="goodsPrice" title="商品价格"></display:column>
<display:column property="goodsQuantity" title="商品数量"></display:column>
<display:column property="goodsType" title="商品类型"></display:column>
<display:column title="操作">
    <a href="GetGoodsInfoServlet?goodsID=${goods.goodsID }">修改</a>
</display:column>
    </display:table>


以上是关键的前台代码
后台如下:
response.setContentType("text/html;charset=GBK");
//获取参数
String goodsType = request.getParameter("goodsType");

System.out.println(goodsType+".................................................................");
GoodsServices goodsServices = (GoodsServices) getbean.getBeanByName(this.getServletContext(), "GoodsServices");
List<Goods> result = goodsServices.getAllGoodsByType(goodsType);
HttpSession session=request.getSession();
session.setAttribute("goodsList", result);
session.setAttribute("goodsType", goodsType);
response.sendRedirect("goodsList.jsp");


DAO代码:
public List<Goods> getAllGoodsByType(final String goodsType) {
final List<Goods> result = new LinkedList<Goods>();

return this.jdbcTemplate.execute("{call getAllGoods(?)}", new CallableStatementCallback<List<Goods>>() {
    @Override
    public List<Goods> doInCallableStatement(CallableStatement cs) throws SQLException, DataAccessException {
System.out.println(goodsType+"_________________________________________________________---");
cs.setString(1, goodsType);
cs.execute();
ResultSet rs = cs.getResultSet();
System.out.println("有... ...1");
while (rs.next()) {
    System.out.println("有... ...2");
    Goods good = new Goods();
    good.setGoodsID(rs.getString("goodsID"));
    good.setGoodsName(rs.getString("goodsName"));
    good.setGoodsPrice(rs.getDouble("goodsPrice"));
    good.setGoodsQuantity(rs.getInt("goodsQuantity"));
    good.setGoodsPicture(rs.getString("goodsPicture"));
    good.setGoodsType(rs.getString("goodsType"));
    good.setGoodsDescription(rs.getString("goodsDescription"));
    result.add(good);
}
return result;
    }
});
    }



run:

???????·.................................................................(此处为servlet的输出提示)

家具用品_________________________________________________________---(此处为dao中的输出提示)

大家如果仔细看到这里会发现我在servlet中没有转码操作才会出现这样的问题

那好,现在进行转码操作:

response.setContentType("text/html;charset=GBK");
//获取参数
request.setCharacterEncoding("GBK"); 仅仅多了这一行代码,post方式提交数据的编码方式
String goodsType = request.getParameter("goodsType");

run:
化妆用品.................................................................(此处为servlet的输出提示)

????_________________________________________________________---(此处为dao中的输出提示)

由于dao中参数为乱码,所以没有从数据库汇总取出值

扶额中QAQ

各位大神看看

你可能感兴趣的:(DAO,jvm,servlet)