2
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 ??

Nishant
  • 54,584
  • 13
  • 112
  • 127
user691197
  • 927
  • 6
  • 20
  • 38

2 Answers2

4

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?

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks it worked with JSTL. But I'm unable to figure out what's wrong with my code !! The Bean class is present in default package so I guess I dont have to import it . Should I use Tag ?? or anything else ? – user691197 Apr 10 '11 at 07:00
  • Classes in default package are unimportable by classes in a package. You should always put classes in a package. And no, you don't need `jsp:useBean` if you're using servlets. – BalusC Apr 10 '11 at 10:52
1

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.

kensen john
  • 5,439
  • 5
  • 28
  • 36