刚刚关注教程并遇到了Spring MVC的一些问题。你能告诉我为什么我的forEach循环出现问题以及如何修复它?
HTTP状态[500] - [内部服务器错误]
类型例外报告
消息在[24]行处理JSP页面[/WEB-INF/views/games.jsp]时发生异常
描述服务器遇到意外情况,导致无法完成请求。
异常 org.apache.jasper.JasperException:在[24]行处理JSP页面[/WEB-INF/views/games.jsp]时发生异常
&#13;&#13;&#13;&#13;&#13;21: 22: <section class="container"> 23: <div class="row"> 24: <c:forEach items="${games}" var="game"> 25: <div class="col-sm-6 col-md-3" style="padding-bottom: 15px"> 26: <div class="thumbnail"> 27: <img src="<c:url value="/resource/images/${game.gameId}.png"></c:url>" alt="image" style = "width:100%"/>
堆栈跟踪: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:588) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:466) 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:742) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1217) org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) javax.servlet.http.HttpServlet.service(HttpServlet.java:635) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
根本原因 javax.servlet.ServletException:javax.servlet.jsp.JspTagException:不知道如何迭代提供的&#34;项目&#34; in&lt; forEach&gt; org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:669) org.apache.jsp.WEB_002dINF.views.games_jsp._jspService(games_jsp.java:169) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) 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:742) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1217) org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) javax.servlet.http.HttpServlet.service(HttpServlet.java:635) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
根本原因 javax.servlet.jsp.JspTagException:不知道如何迭代提供的&#34;项目&#34; in&lt; forEach&gt; org.apache.taglibs.standard.tag.common.core.ForEachSupport.toForEachIterator(ForEachSupport.java:274) org.apache.taglibs.standard.tag.common.core.ForEachSupport.supportedTypeForEachIterator(ForEachSupport.java:238) org.apache.taglibs.standard.tag.common.core.ForEachSupport.prepare(ForEachSupport.java:155) javax.servlet.jsp.jstl.core.LoopTagSupport.doStartTag(LoopTagSupport.java:256) org.apache.jsp.WEB_002dINF.views.games_jsp._jspx_meth_c_005fforEach_005f0(games_jsp.java:193) org.apache.jsp.WEB_002dINF.views.games_jsp._jspService(games_jsp.java:151) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) 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:742) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:209) org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:267) org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1217) org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1005) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:952) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852) javax.servlet.http.HttpServlet.service(HttpServlet.java:635) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837) javax.servlet.http.HttpServlet.service(HttpServlet.java:742) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet"
href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<title>Gry</title>
</head>
<body>
<section>
<div class="jumbotron">
<div class="container">
<h1>Gry</h1>
<p>PS3 PS4 XBOX 360 XBOX ONE</p>
</div>
</div>
</section>
<section class="container">
<div class="row">
<c:forEach items="${games}" var="game">
<div class="col-sm-6 col-md-3" style="padding-bottom: 15px">
<div class="thumbnail">
<img src="<c:url value="/resource/images/${game.gameId}.png"></c:url>" alt="image" style = "width:100%"/>
<div class="caption">
<h3>${game.gameName}</h3>
<p>${game.gameDescription}</p>
<p>${game.gamePrice} PLN</p>
<p>Pozostało: ${game.gamesInStock}</p>
<p>
<a
href=" <spring:url value="/games/game?id=${game.gameId}" /> "
class="btn btn-primary"> <span
class="glyphicon-info-sign glyphicon" /></span> Szczegóły
</a>
</p>
</div>
</div>
</div>
</c:forEach>
</div>
</section>
</body>
</html>
&#13;
package com.kk.gamestore.controller;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.MatrixVariable;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.kk.gamestore.domain.Game;
import com.kk.gamestore.service.GameService;
@RequestMapping("/games")
@Controller
public class GameController {
@Autowired
private GameService gameService;
@RequestMapping
public String Welcome(Model model) {
model.addAttribute("games", gameService.getAllGames());
return "games";
}
@RequestMapping("/all")
public String allGames(Model model) {
model.addAttribute("games", gameService.getAllGames());
return "games";
}
@RequestMapping("/{platform}")
public String getGamesByPlatform(Model model, @PathVariable("platform") String gamePlatform) {
model.addAttribute("games", gameService.getGamesByPlatform(gamePlatform));
return "games";
}
@RequestMapping("/filter/{ByCriteria}")
public String getGamesByFilter(@MatrixVariable(pathVar="ByCriteria")
Map<String,List<String>> filterParams, Model model){
model.addAttribute("games", gameService.getGamesByFilter(filterParams));
return "games";
}
@RequestMapping("/game")
public String getGamesById(@RequestParam("id") String gameId, Model model){
model.addAttribute("games", gameService.getGameById(gameId));
return "games";
}
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String getAddNewGameForm(Model model) {
Game newGame = new Game();
model.addAttribute("newGame", newGame);
return "addGame";
}
@RequestMapping(value = "/add", method = RequestMethod.POST)
public String processAddNewGameForm(@ModelAttribute("newGame") Game gameToBeAdded, BindingResult result) {
String[] suppressedFields = result.getSuppressedFields();
if (suppressedFields.length > 0) {
throw new RuntimeException("Próba wiązania niedozwolonych pól: " + StringUtils.arrayToCommaDelimitedString(suppressedFields));
}
gameService.addGame(gameToBeAdded);
return "redirect:/games";
}
@InitBinder
public void initialiseBinder(WebDataBinder binder) {
binder.setDisallowedFields("unitsInOrder", "discontinued");
}
}
&#13;