问题找到了, 解决办法
1、<%@ page isELIgnored=“false” %>
2、web.xml 头文件信息版本改为2.4
使用<c:foreach>标签直接这样打印…网上也找不到类似的问题,
jsp代码:
<%@ page import="com.ssm.pojo.Items" %>
<%@ page import="java.util.List" %>
<%@ page import="com.ssm.pojo.ItemsCustomer" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>商品列表查询</title>
</head>
<body>
<table border="1" cellpadding="10" cellspacing="0">
<tr>
<td>商品编号</td>
<td>商品名称</td>
<td>商品价格</td>
<td>商品描述</td>
<td>商品图片</td>
<td>创建日期</td>
<td>EDIT</td>
</tr>
<tr>
<c:forEach items="${itemsList}" var="list">
<td>${list.id}</td>
<td>${list.name}</td>
<td>${list.price}</td>
<td>${list.detail}</td>
<td>${list.pic}</td>
<%-- <td><fmt:formatDate value="${list.createtime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>--%>
</c:forEach>
</tr>
</table>
</body>
</html>
controller代码:
package com.ssm.controller;
import com.ssm.pojo.ItemsCustomer;
import com.ssm.service.ItemsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.List;
@Controller
public class ItemsController {
@Autowired
private ItemsService itemsService;
@RequestMapping("/findItemsList")
public ModelAndView findItemsList(){
List<ItemsCustomer> itemsList = itemsService.findItemsList(null);
System.out.println(itemsList.size());
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("itemsList",itemsList);
modelAndView.setViewName("/Items/ItemsList");
return modelAndView;
}
}
这个java代码是没问题的,因为我在jsp使用java代码遍历是没有问题的
<%@ page import="com.ssm.pojo.Items" %>
<%@ page import="java.util.List" %>
<%@ page import="com.ssm.pojo.ItemsCustomer" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>商品列表查询</title>
</head>
<body>
<table border="1" cellpadding="10" cellspacing="0">
<tr>
<td>商品编号</td>
<td>商品名称</td>
<td>商品价格</td>
<td>商品描述</td>
<td>商品图片</td>
<td>创建日期</td>
<td>EDIT</td>
</tr>
<%
//java代码能输出
List<ItemsCustomer> itemsList = (List<ItemsCustomer>) request.getAttribute("itemsList");
for (Items it :itemsList) {
%>
<tr>
<td><%=it.getName()%></td>
<td><%=it.getPrice()%></td>
<td><%=it.getCreatetime()%></td>
<td><%=it.getDetail()%></td>
<td><%=it.getPic()%></td>
<td><%=it.getCreatetime()%></td>
</tr>
<%}%>
</table>
</body>
</html>
效果:
maven工程:有加入依赖包,也把包直接复制到了WEB-INFO下面: