jstl核心标签forEach没有出现在JSP上

问题描述

<h1>Customer Lists</h1>
<div>
    <table border="1">
        <tr>
            <th>Customer Name</th>
            <th>Email</th>
            <th>Password</th>
            <th>Phone</th>
            <th>Country</th>
            <th>Actions</th>
        </tr>

        <c:forEach var="e" items="${listofcustomers}" begin="0">
            <c:url var="deleteLink" value="/deleteCustomer">
                <c:param name="customerId" value="${e.cust_id}" />
            </c:url>
            <c:url var="updateLink" value="/editCustomer">
                <c:param name="customerId" value="${e.cust_id}" />
            </c:url>
            <tr>
                <td>${e.cust_name}</td>
                <td>${e.cust_email}</td>
                <td>${e.cust_pw}</td>
                <td>${e.cust_phone}</td>
                <td>${e.cust_country}</td>
                <td><a href="${updateLink}">Update</a> <a href="${deleteLink}"
                    onclick="if(!(confirm('Are you sure you want to delete '))) return false;">
                        Delete</a></td>
            </tr>
        </c:forEach>


    </table>
    <a href="adminlist">Admin List</a>
</div>

这是控制器类的功能

@RequestMapping("/login")
    public ModelAndView login(@modelattribute("customer") Customer customer,BindingResult result) {
        ModelAndView mav = new ModelAndView();
        try {
            if (customer.getCust_pw().equals("")) {
                result.rejectValue("cust_pw","error.empty.pw");
                mav = new ModelAndView("login");
            }
            else if (customer.getCust_email().equals("")) {
                result.rejectValue("cust_email","error.empty.email");
                return mav = new ModelAndView("login");
            }
            else if (mapper.findByEmail(customer.getCust_email()) == null) {
                result.rejectValue("cust_email","error.mismatch.email");
                mav = new ModelAndView("login");
            }
            else if (!customer.getCust_pw().equals(mapper.checkPw(customer.getCust_email()))) {
                result.rejectValue("cust_pw","error.mismatch.pw");
                mav = new ModelAndView("login");
            }
            else {
                System.out.println(mapper.getAllCustomer());
                mav = new ModelAndView("index");
                mav.addobject("listofcustomers",mapper.getAllCustomer());
            }
        } catch (Exception e) {
            e.printstacktrace();
        }
        return mav;
    }

这是mapper.java的功能

  @Repository
public class CustomerMapper {
    public List<Customer> getAllCustomer() {
        sqlSession session = MyBatilUtil.getsqlSessionFactory().openSession();
        List<Customer> customerList = session.selectList("getAllCustomer");
        session.commit();
        session.close();
        return customerList;
    }

在这个春季的MVC中还是新手。我希望你们能帮助我解决这个问题。 当我尝试使用Spring MVC运行代码时,该页面显示forEach。我已经在jsp上声明了taglib。我的jsp有什么问题吗?还是控制器部分的逻辑?

解决方法

要使用JSTL,请尝试使用以下

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