servlet取到了数据,传到jsp,jsp怎么都取不到?

549663844 2018-10-31 01:12:23
后台这个list debug出来是有数据的 ,是个Object,但是jsp c:foreach不出来,后台换做setSession前台c:foreach就取得到,怎么回事。如果用内嵌的java代码循环这个object,该怎么改写?

package sh.shop.web.servlet.manager;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import sh.shop.domain.Product;
import sh.shop.exception.ListProductException;
import sh.shop.service.ProductService;

@WebServlet("/listProduct")
/**
* 后台
* 查询所有商品信息的servlet
*/
public class ListProductServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
// 1.创建service层的对象
ProductService service = new ProductService();
// 2.调用service层的listAll()
List<Product> list = service.listAll();
// 3.将查询出的所有商品放进request域中
request.setAttribute("list", list);
// 4.将请求转发到list.jsp
request.getRequestDispatcher("/admin/products/list.jsp").forward(
request, response);
return;
} catch (ListProductException e) {
e.printStackTrace();
response.getWriter().write(e.getMessage());
return;
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
}


<tbody>
<c:forEach items="${list}" var="p">
<tr class="text-c va-m">
<td><input name="" type="checkbox" value=""></td>
<td>${p.id }</td>
<td><a onClick="" href="javascript:;"><img width="60" class="product-thumb" src=""></a></td>
<td class="text-l"><a style="text-decoration:none" onClick="" href="javascript:;">${p.name }</a></td>
<td class="text-l">${p.description }</td>
<td>${p.price }</td>
<td>${p.category }</td>
<td class="td-manage"><a style="text-decoration:none" class="ml-5" onClick="product_edit('产品编辑','product-add.html','10001')" href="javascript:;" title="编辑"><i class="Hui-iconfont"></i></a> <a style="text-decoration:none" class="ml-5" onClick="product_del(this,'10001')" href="javascript:;" title="删除"><i class="Hui-iconfont"></i></a></td>
</tr>
</c:forEach>
</tbody>


...全文
1003 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
热爱生活~~~ 2018-11-21
  • 打赏
  • 举报
回复
引用 7 楼 wxb_hz 的回复:
你这get方法是void类型的,而且看你代码返回给前台是应的 request.setAttribute("list", list);还要return干嘛? 而且你throws ServletException, IOException 和try catch 只要一种就可以了。
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		 // 1.创建service层的对象
                ProductService service = new ProductService();
                // 2.调用service层的listAll()
                List<Product> list = service.listAll();
                // 3.将查询出的所有商品放进request域中
                request.setAttribute("list", list);
                // 4.将请求转发到list.jsp
                request.getRequestDispatcher("/admin/products/list.jsp").forward(
                                request, response);
	}
热爱生活~~~ 2018-11-21
  • 打赏
  • 举报
回复
你这get方法是void类型的,而且看你代码返回给前台是应的 request.setAttribute("list", list);还要return干嘛? 而且你throws ServletException, IOException 和try catch 只要一种就可以了。
Thinking~ 2018-11-21
  • 打赏
  • 举报
回复
https://blog.csdn.net/qzw5235641/article/details/84309438
邓郴2019 2018-11-10
  • 打赏
  • 举报
回复
加return干嘛?
_jant 2018-11-08
  • 打赏
  • 举报
回复
el标签获取 域内值 了解一下
唐_方 2018-11-08
  • 打赏
  • 举报
回复
你抛出啦异常就不用再捕捉异常啦,把try catch去掉, 不用return 试试可以吗
ninuxGithub 2018-11-07
  • 打赏
  • 举报
回复
有必要加return 吗 ? request里面的值无法达到页面
H-arry 2018-11-02
  • 打赏
  • 举报
回复
试下直接在方法上抛出异常,然后response这个对象不要调用他,也就是捕获异常中的几行代码全删了。

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧