如何解决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" %>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。