public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String searchName= new String(request.getParameter("txtPname").getBytes("ISO8859-1"),"UTF-8");
ProductDao productDao = new ProductDao();
try {
ArrayList<Product> productList = productDao.search(searchName);
HttpSession session = request.getSession();
session.setAttribute("productList", productList);
if(productList.isEmpty()){
productList = null;
productList=productDao.selectAll();
session= request.getSession();
session.setAttribute("productList", productList);
request.getRequestDispatcher("/ProductList.jsp").forward(request, response);
//想在这里加入输出到页面的String

}else{
request.getRequestDispatcher("/ProductList.jsp").forward(request, response);
}
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

解决方案 »

  1.   

    request.getRequestDispatcher("/ProductList.jsp").forward(request, response); 
    这个已经跳转了、在跳转前加不行吗?
      

  2.   

    跳转前那就session.setAttribute、 request.setAttribute等等、、、、都行了
      

  3.   

    上面说的有道理,把值保存在attritute里面然后在页面上取出来,打印出来就好了
      

  4.   

    抱歉,我是初学者,刚接触,所以能否能详细点,最好JSP页面的也可以有点,谢谢了~
      

  5.   


    if(productList.isEmpty()){
    productList = null;

    String a = "商品信息有误";
    productList=productDao.selectAll();
    session= request.getSession();
    session.setAttribute("productList", productList);
    session.setAttribute("a", a);
    request.getRequestDispatcher("/ProductList.jsp").forward(request, response);这里加入这一段,不知道哪里有问题,页面总是显示为NULL
      

  6.   

    额,OK了,原来是在页面request.setCharacterEncoding("UTF-8");的问题。谢谢两位了~