4

I'm following the Spring MVC course from VirtualPairProgrammers and the workspace they have provided seems to have some issues. I'm getting the following error when I run the code.

org.apache.jasper.JasperException: Unable to compile class for JSP: An error occurred at line: 1 in the generated java file The type java.io.ObjectInputStream cannot be resolved. It is indirectly referenced from required .class files

Any ideas what is going wrong? This is the code in my controller:

@RequestMapping("/viewAllBooks")
public ModelAndView viewAllBooks()
{
    List<Book> allBooks = bookService.getEntireCatalogue();
    return new ModelAndView("/displayAllBooks.jsp","allBooks",allBooks);
}

And this is the JSP file:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>


<html>
<head>
    <title>All books for our store</title>
    <link href="styles.css" rel="Stylesheet" type="text/css"/>
</head>

<body>

    <jsp:include page="/web/header.jsp"/>

    <div id="books">
        <ul>
            <c:forEach items="${allBooks}" var="nextBook">

            <li>
                <h2>${nextBook.title}</h2>
                <p>
                    <span> by  ${nextBook.author}  
                           <fmt:formatNumber value="${nextBook.price}"
                                             type="currency"
                                             currencyCode="USD" />          

                    <form method='post' action='<c:url value=""/>'>
                        <input type='hidden' name='id' value='${nextBook.id}'/>
                        <input type='image' src='cart-button.png'/>
                    </form>
                </span>
                </p>

            </li>

            </c:forEach>

        </ul>
    </div>

    <jsp:include page="/web/footer.jsp"/>

</body>

</html>
Lithicas
  • 3,793
  • 7
  • 23
  • 32
  • 2
    What's your Java version? Looks like there is a problem with versions 1.8.0_91 and after. – emrahkocaman May 02 '16 at 13:15
  • Red Hat issue: https://access.redhat.com/solutions/2294701 – mzjn May 03 '16 at 09:27
  • @mzjn, any idea what the workaround is? – Martin Serrano May 03 '16 at 16:18
  • @Martin Serrano: The suggested resolution is "Consider precompiling JSPs as a workaround". There is also a link to a reopened bug report (1223609) and note that says "ecj is an older version that does not support java 8". I don't know what to make of that. There was no problem with Java 8 Update 77 AFAIK. – mzjn May 09 '16 at 05:49
  • See also http://stackoverflow.com/q/36963248/407651 – mzjn May 09 '16 at 08:29

1 Answers1

0

I designed the course so I should be able to help. We supply a copy of Tomcat that was current at the time of recording, and this has been ok for a number of years. However Java 8 breaks on this version. It should be a simple case of running the code on Tomcat 8.

I'll contact you through VirtualPairProgrammers and when we've sorted out the version mismatch we'll update the course to use Tomcat 8.

Dick Chesterwood
  • 2,629
  • 2
  • 25
  • 33
  • 1
    But Java 1.8.0_77 (the update before 1.8.0_91) is also Java 8. It does not break in that version, does it? Things should not break like this between two updates within the same major version. – mzjn Aug 22 '16 at 12:49
  • 1
    Agreed, I did wonder why we haven't seen this problem until very recently. It's all a bit confusing but according to the compatibility chart at http://tomcat.apache.org/whichversion.html, only Tomcat 9 supports Java 8. This solves the problem for the course mentioned above, I'm not sure what the underlying problem is. – Dick Chesterwood Aug 23 '16 at 11:48
  • 1
    You might be interested in this (tentative) answer to a related question: http://stackoverflow.com/a/38444118/407651. – mzjn Aug 23 '16 at 12:32
  • 1
    Thanks mzjn, it's clearly causing a bit of chaos this one! – Dick Chesterwood Aug 23 '16 at 14:22