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

549663844 549663844 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
后台这个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>


...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
549663844
Web 开发 81,107 成员 341,720 内容