我正在尝试迭代列表,但它不起作用。这是一项基本操作,但我找不到问题。
@RequestMapping(value = "/home", method = RequestMethod.GET)
public ModelAndView home(HttpServletRequest request) {
ModelAndView mav = new ModelAndView("home");
UserModel user = sm.get(request);
mav.addObject("user", user);
try {
List<ArticleModel> articles = articleDao.listFiveArticles();
mav.addObject("articles", articles);
return mav;
} catch (Exception e) {
e.getMessage();
e.printStackTrace();
return mav;
}
}
我正试图在jsp中迭代overarticles列表
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<jsp:include page="menu.jsp" />
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Начало</title>
</head>
<body>
<c:if test="${not empty articles}">
<c:forEach var="a" items="${articles}">
<p>
<b>${a.article_name}</b>
</p>
<p>${a.article_body}</p>
<p>
<i>Публикувал:</i> <a
href="<c:url value="/all-articles?name="/>${a.article_author}">${a.article_author}</a>
</p>
<hr>
</c:forEach>
</c:if>
</body>
</html>
但我有这个例外
编辑:这是完整的堆栈跟踪。我调试并检查文章列表。它肯定不是空的!
java.lang.NumberFormatException: For input string: "article_name"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
java.lang.Integer.parseInt(Integer.java:580)
java.lang.Integer.parseInt(Integer.java:615)
javax.el.ArrayELResolver.coerce(ArrayELResolver.java:144)
javax.el.ArrayELResolver.getValue(ArrayELResolver.java:61)
org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)
org.apache.el.parser.AstValue.getValue(AstValue.java:169)
org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:944)
org.apache.jsp.WEB_002dINF.views.home_jsp._jspx_meth_c_005fforEach_005f0(home_jsp.java:221)
org.apache.jsp.WEB_002dINF.views.home_jsp._jspx_meth_c_005fif_005f0(home_jsp.java:182)
org.apache.jsp.WEB_002dINF.views.home_jsp._jspService(home_jsp.java:141)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:168)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1257)
org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)