0

I´m trying to implement JSP & JSTL into my fresh spring boot application, but run into an error.

Current Setup:

In pom.xml i added:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
</dependency>

<!-- Need this to compile JSP -->
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
</dependency>

Within the AppConfig this is added:

@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
    InternalResourceViewResolver resolver = new InternalResourceViewResolver();
    resolver.setPrefix("/WEB-INF/view/");
    resolver.setSuffix(".jsp");
    resolver.setViewClass(JstlView.class);
    registry.viewResolver(resolver);
}

The Test-Controller / called function is Setup like that:

@RequestMapping(path = "/listtest")
public String listTest(Model model) {
    List<String> itemsTest = new ArrayList<>();

    for(int i = 0; i < 300; i++){
        itemsTest.add("test-Item "  + i );
    }

    model.addAttribute("itemsTest", testItems);

    return "items/testlist";
}

In test testlist.jsp i added this:

<!DOCTYPE HTML>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

   <html lang="de">
   <head>
   <title>JSP TEST</title>
   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<table>
   <tr>
      <th>Column #1</th>
      <th>Column #2</th>
      <th>Column #3</th>
    </tr>
    <c:forEach items="${itemsTest}" var="testItem">
       <tr>
           <td><c:out value="${testItem}"/></td>
           <td><c:out value="${testItem}"/></td>
           <td><c:out value="${testItem}"/></td>
        </tr>
    </c:forEach>
 </table>
</body>

Until the last Item, everything is working fine, but then two Exceptions are thrown:

Servlet.service() for servlet [jsp] threw exception

java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;
    at javax.servlet.jsp.jstl.core.LoopTagSupport.unExposeVariables(LoopTagSupport.java:587) ~[jstl-1.2.jar:1.2]
    at javax.servlet.jsp.jstl.core.LoopTagSupport.doFinally(LoopTagSupport.java:323) ~[jstl-1.2.jar:1.2]
    at org.apache.jsp.WEB_002dINF.view.items.testlist_jsp._jspx_meth_c_005fforEach_005f0(testlist_jsp.java:134) ~[na:na]
    at org.apache.jsp.WEB_002dINF.view.items.testlist_jsp._jspService(testlist_jsp.java:72) ~[na:na]

And

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;] with root cause

java.lang.AbstractMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;
    at javax.servlet.jsp.jstl.core.LoopTagSupport.unExposeVariables(LoopTagSupport.java:587) ~[jstl-1.2.jar:1.2]
    at javax.servlet.jsp.jstl.core.LoopTagSupport.doFinally(LoopTagSupport.java:323) ~[jstl-1.2.jar:1.2]
    at org.apache.jsp.WEB_002dINF.view.items.testlist_jsp._jspx_meth_c_005fforEach_005f0(testlist_jsp.java:134) ~[na:na]
    at org.apache.jsp.WEB_002dINF.view.items.testlist_jsp._jspService(testlist_jsp.java:72) ~[na:na]
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98) ~[jasper-runtime-5.5.23.jar:na]

Thats the output of the last two loops:

lastlines-output

What am i doing wrong?

develth
  • 771
  • 8
  • 32
  • Can you provide some sample input and expected output? My guess at the moment is that you ran outta bounds in the loop – Mike Tung Nov 06 '17 at 13:57
  • The input is created at the second code example, the output with a screenshot at the end of this question. – develth Nov 06 '17 at 13:58
  • Do you have any configuration for your JSPs, if so can you provide it? If not the lack of could be the problem. – craigwor Nov 06 '17 at 14:17
  • Just in application.properties spring.mvc.view.prefix=/WEB-INF/view/ spring.mvc.view.suffix=.jsp – develth Nov 06 '17 at 14:19
  • And in the AppConfiguration, i add it now. Thanks for the hint. – develth Nov 06 '17 at 14:21
  • No problem. Let me know the outcome. – craigwor Nov 06 '17 at 14:27
  • It was already added in my code, i just added it to this question - so still not working as described. – develth Nov 06 '17 at 14:31
  • 1
    @develth sas I gone through you code, if it's exactly same, seems having no problem.. you must see this answer once.. https://stackoverflow.com/a/7274928/6446770 hope it helps. Hint: problem maybe with the JSTL/Spring libraries or conflicts. – miiiii Nov 06 '17 at 14:33
  • Ok - will check it out. Thanks. But really confusing, because it outputs the content in the foreach until the last item. – develth Nov 06 '17 at 14:34
  • Ok - pretty fancy. Moved the jstl import to the top of the pom.xml - works! – develth Nov 06 '17 at 14:55

0 Answers0