简体   繁体   中英

JSP Compilation Error

Object mainForumRecords=request.getAttribute("mainForumRecords");

    if(mainForumRecords instanceof ArrayList)
    {

        Iterator<MainForumRecordBean> recordIterator=((ArrayList<MainForumRecordBean>)mainForumRecords).listIterator();
        while(recordIterator.hasNext())
        {
            out.println("<tr>");
            MainForumRecordBean record=recordIterator.next();
            {
                MainForumRecordBean mainForumRecord=(MainForumRecordBean)record;
                out.print("<td>");
                out.print(mainForumRecord.getMainPostId());
                out.print("</td>");
                out.print("<td>");
                out.print(mainForumRecord.getPostHeading());
                out.print("</td>");
                out.print("<td>");
                out.print(mainForumRecord.getPostText());
                out.print("</td>");
                out.print("<td>");
                out.print(mainForumRecord.getAuthorId());
                out.print("</td>");
                out.print("<td>");
                out.print(mainForumRecord.getTimeStamp());
                out.print("</td>");
            }
            out.println("</tr>");
        }
    }

I am getting an error in the above JSP code.

org.apache.jasper.JasperException: PWC6033: Error in Javac compilation for JSP

PWC6197: An error occurred at line: 32 in the jsp file: /loginIndex.jsp
PWC6199: Generated servlet error:
string:///loginIndex_jsp.java:85: cannot find symbol
symbol  : class MainForumRecordBean
location: class org.apache.jsp.loginIndex_jsp

PWC6197: An error occurred at line: 32 in the jsp file: /loginIndex.jsp
PWC6199: Generated servlet error:
string:///loginIndex_jsp.java:85: cannot find symbol
symbol  : class MainForumRecordBean
location: class org.apache.jsp.loginIndex_jsp

PWC6197: An error occurred at line: 32 in the jsp file: /loginIndex.jsp
PWC6199: Generated servlet error:
string:///loginIndex_jsp.java:89: cannot find symbol
symbol  : class MainForumRecordBean
location: class org.apache.jsp.loginIndex_jsp

PWC6197: An error occurred at line: 32 in the jsp file: /loginIndex.jsp
PWC6199: Generated servlet error:
string:///loginIndex_jsp.java:91: cannot find symbol
symbol  : class MainForumRecordBean
location: class org.apache.jsp.loginIndex_jsp

PWC6197: An error occurred at line: 32 in the jsp file: /loginIndex.jsp
PWC6199: Generated servlet error:
string:///loginIndex_jsp.java:91: cannot find symbol
symbol  : class MainForumRecordBean
location: class org.apache.jsp.loginIndex_jsp

I have tried removing Parameterized cast in ArrayList of Iterator object. But I've got error even then. Can anyone help me with this ??

Also when writing raw Java code in a JSP file instead of a Java class, you still need to import the class like as you would do in a normal Java class.

<%@page import="com.example.MainForumRecordBean" %>

Otherwise you would get cannot find symbol errors like as you would get in a normal Java class when not importing the class.


However, the entire approach is pretty clumsy. I'd suggest to get rid of the old fashioned Scriptlets and just use JSTL/EL. The same can be achieved as follows:

<%@taglib prefic="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<table>
    <c:forEach items="${mainForumRecords}" var="mainForumRecord">
        <tr>
            <td>${mainForumRecord.mainPostId}</td>
            <td>${mainForumRecord.postHeading}</td>
            <td>${mainForumRecord.postText}</td>
            <td>${mainForumRecord.authorId}</td>
            <td>${mainForumRecord.timeStamp}</td>
        </tr>
    </c:forEach>
</table>

Much more concise and better readable/maintainable, isn't it?

This happens, when you have deployed new class files/Servlets but have not restarted the server instance.

If you do not restart the server, the compiled class files will not get loaded, and jsps will not compile.

So the solution is to first check if you have moved the compiled classes/servlets. Then restart the server instance.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM