【问题标题】:jstl core tag forEach doesn't appeared on JSPjstl 核心标签 forEach 没有出现在 JSP 上
【发布时间】:2020-12-20 09:36:25
【问题描述】:
<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有什么问题吗?或者可能是控制器部分的逻辑?

【问题讨论】:

  • 向我们展示整个视图以及负责将数据传递到该视图的控制器。还要确保你的 taglib 看起来像这样 &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
  • @maciejd 我刚刚编辑了页面,我真的不知道您是否需要查看,但这就是当前为页面运行的所有功能。

标签: spring-mvc jstl jsp-tags


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 2018-12-21
    • 1970-01-01
    • 2013-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多