好的,我已经尝试了一个小时的工作,我确信这很容易,但我认为我对自己的代码视而不见。此页面应该只检索发送到由mysql查询检索到的Arraylist的数据。这是Tomcat日志:
06-Mar-2016 20:42:26.465 SEVERE [http-nio-8084-exec-12] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [RatingServlet] in context with path [] threw exception [An exception occurred processing JSP page /ratinglist.jsp at line 50
47: <tr>
48: <td>${newrating.scale}</td>
49: <td>${newrating.userid}</td>
50: <td>${newrating.text_rating}</td>
51: <td></td>
52: <%-- <td>${newrating.text_rating}</td> --%>
53: <td></td>
Stacktrace:] with root cause
javax.el.PropertyNotFoundException: Property 'text_rating' not found on type edu.csueb.cs6665.bean.Ratings
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:245)
at javax.el.BeanELResolver$BeanProperties.access$300(BeanELResolver.java:222)
at javax.el.BeanELResolver.property(BeanELResolver.java:332)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:95)
at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:110)
at org.apache.el.parser.AstValue.getValue(AstValue.java:167)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:187)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:956)
at org.apache.jsp.ratinglist_jsp._jspx_meth_c_005fforEach_005f0(ratinglist_jsp.java:173)
at org.apache.jsp.ratinglist_jsp._jspService(ratinglist_jsp.java:116)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:405)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:349)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:721)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:466)
at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:391)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
at edu.csueb.cs6665.servlet.RatingServlet.processRequest(RatingServlet.java:127)
at edu.csueb.cs6665.servlet.RatingServlet.doGet(RatingServlet.java:144)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:503)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:136)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:526)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1078)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:655)
at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:222)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1566)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1523)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
这就是我所拥有的:
ratinglist.jsp
<body>
<jsp:include page="/include/header.jsp"/>
<div class="container">
<h1>Videos List</h1>
<table class="table table-striped tablesorter">
<thead>
<tr>
<th>Scale</th>
<th>User</th>
<th>Date</th>
<th>Comment</th>
<th>Video</th>
</tr>
</thead>
<tbody>
<c:forEach var="newrating" items="${newrating}">
<tr>
<td>${newrating.scale}</td>
<td>${newrating.userid}</td>
<td>${newrating.text_rating}</td>
<td></td>
<%-- <td>${newrating.text_rating}</td> --%>
<td></td>
<%-- <td>${newrating.video_id}</td> --%>
<td></td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</body>
RatingServlet.java
package edu.csueb.cs6665.servlet;
import edu.csueb.cs6665.bean.Ratings;
import edu.csueb.cs6665.bean.User;
import edu.csueb.cs6665.util.RatingUtil;
import edu.csueb.cs6665.util.UserUtils;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
*
* @author Shawn
*/
public class RatingServlet extends HttpServlet {
/**
* Processes requests for both HTTP <code>GET</code> and <code>POST</code>
* methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String dispatcher="/rating.jsp";
String role = request.getParameter("role");
String action = request.getParameter("action");
if(null != action && action.equals("delete")){
int id = Integer.parseInt(request.getParameter("id"));
if(id>=0){
boolean status = RatingUtil.removeRatingByid(id);
}
}
if(null != action && action.equals("update2")){
System.out.println("INSIDE Rating update2");
Integer id = Integer.parseInt(request.getParameter("id"));
Integer scale = Integer.parseInt(request.getParameter("scale"));
Integer user_id = Integer.parseInt(request.getParameter("user_id"));
String timedate_rating = request.getParameter("timedate_rating");
String text_rating = request.getParameter("text_rating");
Integer video_id = Integer.parseInt(request.getParameter("video_id"));
if(id>=0){
boolean status = RatingUtil.updateRatingById(scale, user_id, timedate_rating, text_rating, video_id, id);
}
}
if(null != action && action.equals("update")){
Integer id = Integer.parseInt(request.getParameter("id"));
Integer scale = Integer.parseInt(request.getParameter("scale"));
Integer userid = Integer.parseInt(request.getParameter("user_id"));
String ratingdate = request.getParameter("timedate_rating");
String text = request.getParameter("text_rating");
Integer videoid = Integer.parseInt(request.getParameter("video_id"));
if(null != id){
Ratings rating = new Ratings();
rating.setId(id);
rating.setScale(scale);
rating.setUserid(userid);
rating.setTimedate(ratingdate);
rating.setRating(text);
rating.setVideo(videoid);
request.setAttribute("newrating", rating);
dispatcher="/ratingupdate.jsp";
}
}
if(null != action && action.equals("insert")){
Integer scale = Integer.parseInt(request.getParameter("scale"));
Integer userid = Integer.parseInt(request.getParameter("user_id"));
String ratingdate = request.getParameter("timedate_rating");
String text = request.getParameter("text_rating");
Integer videoid = Integer.parseInt(request.getParameter("video_id"));
Ratings rating = new Ratings(scale, userid, ratingdate, text, videoid);
//product.setReleasedate(releasedate);
if(null != scale){
boolean status = RatingUtil.insertRating(rating);
}
}
if(action.equals("load")){
System.out.println("Inside RatingServlet, loading");
List<Ratings> rating = RatingUtil.getRatings();
request.setAttribute("newratings", rating);
if(role=="user"){
dispatcher="/ratinglist.jsp";
}
}
if(action.equals("list")){
System.out.println("Inside RatingServlet, listing");
List<Ratings> rating = RatingUtil.getRatings();
request.setAttribute("newrating", rating);
dispatcher="/ratinglist.jsp";
}
List<Ratings> rating = RatingUtil.getRatings();
request.setAttribute("newrating", rating);
this.getServletContext().getRequestDispatcher(dispatcher).forward(request, response);
}
Rating.java
package edu.csueb.cs6665.bean;
import java.util.Date;
import java.io.Serializable;
/**
*
*/
public class Ratings implements Serializable{
private int id;
private int scale;
private int user_id;
private int video_id;
private String timedate_rating;
private String text_rating;
public Ratings(){
}
public Ratings(int scale, int user_id, String timedate_rating, String text_rating, int video_id) {
this.setScale(scale);
this.setUserid(user_id);
this.setTimedate(timedate_rating);
this.setRating(text_rating);
this.setVideo(video_id);
}
public Ratings(int scale, int user_id, String timedate_rating, String text_rating, int video_id, int id) {
this.setScale(scale);
this.setUserid(user_id);
this.setTimedate(timedate_rating);
this.setRating(text_rating);
this.setVideo(video_id);
this.setId(id);
}
public int getScale() {
return scale;
}
public void setScale(int scale) {
this.scale = scale;
}
public int getId() {
return id;
}
public void setId(int id) {
this.user_id = id;
}
public int getUserid() {
return user_id;
}
public void setUserid(int user_id) {
this.user_id = user_id;
}
public String getTimedate() {
return timedate_rating;
}
public void setTimedate(String timedate) {
this.timedate_rating = timedate;
}
public String getRating() {
return text_rating;
}
public void setRating(String text_rating) {
this.text_rating = text_rating;
}
public int getVideo() {
return video_id;
}
public void setVideo(int video_int) {
this.video_id = video_int;
}
}
答案 0 :(得分:1)
如果我不得不猜测它是因为text_rating的等级中变量和getter / setter的命名方式。你可以尝试重命名getter和setter getTextRating和setTextRating,看看是否有诀窍。它可能无法在.jsp中获取text_rating,因为没有与该名称匹配的getter(仅限getRating)。