0

I am a newbie working on a Java-JSP web site. Manually refreshing a JSP page repeatedly returns an error once out of 4 or 5 refreshes. All the other attempts renders the page successfully. No changes have been performed on the JSP. I'm stumped. Can anybody provide some insight? I can provide more info if required. Thank you very much.

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 97 in the jsp file: /uploadedDocs.jsp
The method getAllDocuments() is undefined for the type Documents
94:                         width="100%">
95:                         <tr class="tablehead">
96:                             <td colspan=6>UPLOADED     FILES</td>
97:                             <%=documents.getAllDocuments()%>
98:                         </tr>
99:                         <tr class="tablehead">
100:                            <td colspan=6>UPLOAD FILE</td>


Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:443)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:356)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:321)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)

My JSP page has an embedded Java method call to fetch a list of documents uploaded in a database.

<jsp:useBean id="documents" class="com.test.Documents" />
<%documents.initBean(request, response, session, application);%>
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • Best to [avoid scriptlets in JSPs](http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files/3180202#3180202) – GriffeyDog Feb 10 '14 at 21:58

1 Answers1

1

The stacktrace describes the error very well: The method getAllDocuments() is undefined for the type Documents. Verify that your Documents class has this method defined. If it does, make sure to rebuild all your sources and do a clean deploy in your application server.


Not related with your current problem, it would be better if you can stop using scriplets since their use is discouraged from more than 10 years ago (see here for more info: How to avoid Java code in JSP files?).

Since the method getAllDocuments() seems to return a list of Documents, you can use JSTL <c:forEach> to display them accordingly:

<tr class="tablehead">
    <td colspan=6>UPLOADED     FILES</td>
    <%-- =documents.getAllDocuments() --%>

    <c:forEach items="${documents.allDocuments}" var="doc">
        <%-- naive way to print the name of the document (assuming you have a name property) --%>
        ${doc.name}
        <br />
    </c:forEach>
</tr>
Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • Thank you for your response. Rebuilding sources and a clean deploy made the page relatively more consistent (does not render data now) but returns two different errors on refreshes: 1. Unable to compile class for JSP and 2. Unable to load class for JSP. Though they seem quite straightforward to fix. Let me get to it now. I'll also look at replacing the Java Code with JSTL. Thank you very much for your time. – user2256745 Feb 10 '14 at 22:28