Использование JSP ForEach - PullRequest
0 голосов
/ 12 марта 2019

Я разработал приложение, которое извлекает данные из базы данных с помощью hibernateORM. Из-за ошибки я обнаружил ошибку в foreachloop в файле jsp. Я не понял, в чем дело.Имя «ученики» - это название модели, в которой я создал класс StudentController. У меня есть Студенческий класс, в который я помещаю частные переменные с геттерами и сеттерами.

Файл JSP

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
     <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
     <div>
     <h2>Student List</h2>
     </div>
      <div>
     <table>
     <tr>
       <th>First Name</th>
              <th>Last Name</th>
              <th>Email Address</th>

     </tr>
     <c:forEach var="tempStudent" items="${students}">
     <tr>
     <td>${tempStudent.firstName}</td>
      <td>${tempStudent.lastName}</td>
       <td>${tempStudent.email}</td>
     </tr>
     </c:forEach>    
     </table>
     </div>
</body>
</html>

Ошибка

HTTP Status 500 - An exception occurred processing JSP page /WEB-INF/view/list-student.jsp at line 24


type Exception report

message An exception occurred processing JSP page /WEB-INF/view/list-student.jsp at line 24

description The server encountered an internal error that prevented it from fulfilling this request.

exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /WEB-INF/view/list-student.jsp at line 24

21:      </tr>
22:      <c:forEach var="tempStudent" items="${students}">
23:      <tr>
24:      <td>${tempStudent.firstName}</td>
25:       <td>${tempStudent.lastName}</td>
26:        <td>${tempStudent.email}</td>
27:      </tr>


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:574)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    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:170)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:314)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1325)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1069)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1008)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


root cause
javax.el.PropertyNotFoundException: Property 'firstName' not found on type com.timucin.springdemo.entity.Student
    javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:268)
    javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:221)
    javax.el.BeanELResolver.property(BeanELResolver.java:355)
    javax.el.BeanELResolver.getValue(BeanELResolver.java:95)
    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:943)
    org.apache.jsp.WEB_002dINF.view.list_002dstudent_jsp._jspx_meth_c_005fforEach_005f0(list_002dstudent_jsp.java:186)
    org.apache.jsp.WEB_002dINF.view.list_002dstudent_jsp._jspService(list_002dstudent_jsp.java:140)
    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:438)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    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:170)
    org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:314)
    org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1325)
    org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1069)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1008)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


note The full stack trace of the root cause is available in the Apache Tomcat/8.0.36 logs.


Apache Tomcat/8.0.36
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...