Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java jstl标签<;c:forEach不工作了_Java_Spring - Fatal编程技术网

Java jstl标签<;c:forEach不工作了

Java jstl标签<;c:forEach不工作了,java,spring,Java,Spring,我想显示来自产品表的所有可用产品,以显示在此页面上。我的jstl核心标记库添加到头文件中 productList.jsp <%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <%@include file="header.jsp"%> <div class="container-wrapper"> <div class="container">

我想显示来自产品表的所有可用产品,以显示在此页面上。我的jstl核心标记库添加到头文件中

productList.jsp

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@include file="header.jsp"%>

<div class="container-wrapper">
    <div class="container">
        <div class="page-header">
            <h1>All Products</h1>

            <p class="lead">Checkout all the awesome products available now!</p>
        </div>

        <table class="table table-striped table-hover">
            <thead>
            <tr class="bg-success">

                <th>Product Code</th>
                <th>Product Name</th>
                <th>Product Price</th>
                <th></th>
            </tr>
            </thead>
            <c:forEach items="${products}" var="product">
                <tr>
                    <td>${product.code}</td>
                    <td>${product.name}</td>
                    <td>${product.price}</td>
                    <td><a href="<spring:url 
                    value="/product/viewProduct/${product.productId}" />"
                   > <span class="glyphicon glyphicon-info-sign"></span></a></td>
                </tr>
            </c:forEach>
        </table>
<jsp:include page="footer.jsp" />

所有产品

立即查看所有精彩产品

产品代码 品名 产品价格 ${product.code} ${product.name} ${product.price}
我的productController正在返回产品列表

productcontroller

@Controller
public class ProductController {
    @Autowired
    ProductServiceImpl productService;

    @RequestMapping(value="addProduct")
    public String addProduct(){
        return ("addProduct");
    }

    @RequestMapping(value = "/saveProduct")
    public String saveProduct(@ModelAttribute("product") Product productInfo){
        productService.sace(productInfo);
        return ("addProduct");
    }
    @RequestMapping(value = "/productList", method = RequestMethod.GET)
    public String productList(Model model){
        List<Product> productInfoList=productService.productList();   
        model.addAttribute("products",productInfoList);

        return "productList";
    }
}
@控制器
公共类产品控制器{
@自动连线
ProductServiceImpl productService;
@请求映射(value=“addProduct”)
公共字符串addProduct(){
退货(“添加产品”);
}
@请求映射(value=“/saveProduct”)
公共字符串saveProduct(@modeldattribute(“product”)product productInfo){
productService.sace(productInfo);
退货(“添加产品”);
}
@RequestMapping(value=“/productList”,method=RequestMethod.GET)
公共字符串productList(模型){
List productInfoList=productService.productList();
model.addAttribute(“产品”,productInfoList);
返回“产品列表”;
}
}
当我在调试模式下运行这段代码时,我可以清楚地看到dao返回产品列表,所以从数据库中获取数据并没有问题

productDao

@Repository
public class ProductDaoImpl implements ProductDao {
    @Autowired
    SessionFactory sessionFactory;
    Session session;
    Transaction tx;

    public List<Product> productionList() {
        session=sessionFactory.openSession();
        List<Product> productList=session.createQuery("from Product").list();
        return productList;
    }


}
@存储库
公共类ProductDaoImpl实现ProductDao{
@自动连线
会话工厂会话工厂;
会议;
交易发送;
公共列表productionList(){
session=sessionFactory.openSession();
List productList=session.createQuery(“来自产品”).List();
返回产品列表;
}
}
pom.xml上的依赖项列表如下

pom.xml

<dependencies>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>4.3.8.RELEASE</version>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>4.3.8.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>4.3.8.RELEASE</version>

    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>4.3.8.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>4.3.8.RELEASE</version>
    </dependency>

    <!-- https://mvnrepository.com/artifact/org.springframework/spring-orm -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-orm</artifactId>
      <version>4.3.8.RELEASE</version>
    </dependency>

    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-core</artifactId>
      <version>5.2.1.Final</version>
    </dependency>

    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.36</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/taglibs/standard -->
    <dependency>
      <groupId>taglibs</groupId>
      <artifactId>standard</artifactId>
      <version>1.1.2</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>2.5</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>

org.springframework

.jsp
页面顶部添加以下行,然后再次检查

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

.jsp
页面顶部添加以下行,然后再次检查

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

实际上,当我不知道您的所有代码或流程时,很难回答。然而,我在过去使用jstl标记时也遇到了一个错误。请尝试在“header.jsp”文件中替换此文件:


你可以在这里看到区别,我们添加了“core\u rt”而不是“core”。希望有帮助

实际上,当我不知道您的所有代码或流程时,很难回答。然而,我在过去使用jstl标记时也遇到了一个错误。请尝试在“header.jsp”文件中替换此文件:

你可以在这里看到区别,我们添加了“core\u rt”而不是“core”。希望有帮助

添加以下行

EL在web2.5版本中关闭,添加以下行


EL在版本web2.5中已关闭

这已添加到header.jsp文件中,并且header.jsp文件包含在productlist.jsp中。请再次检查好吗?我已经检查并验证了多次。即使我在productlist.jsp文件中添加jstl核心标记库,它也不会工作。我很惊讶。你的getter和setter方法对
产品
模型正确吗?请将你的
web.xml
文件与你的问题一起添加。这已经添加到header.jsp文件中,header.jsp文件包含在productlist.jsp中。你能再次检查吗?我已经检查并验证了多次。即使我在productlist.jsp文件中添加jstl核心标记库,它也不会工作。我很惊讶。你的getter和setter方法对
产品
模型正确吗?请将你的
web.xml
文件添加到你的问题中。请同时显示你的web.xml。当servlet规范版本设置过低时,这通常是一个问题。请同时显示您的web.xml。当servlet规范版本设置得太低时,这通常是一个问题。