2

I have a spring controller in which I am returning a Map named "model"; model contains some set of values but importantly also contains an ArrayList. Now I am returning this Map to my JSP, while using JSTL in my JSP to fetch the ArrayList it throws error.

<c:forEach items="${model.result}" var="data" varStatus="status"> <!-- result is my ArrayList -->
    <c:out value="${data.url}" /> <!-- here url is data inside my result arraylist -->
</c:forEach> 

The error generated is:

root cause 

java.lang.NoSuchMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;
    at javax.servlet.jsp.jstl.core.LoopTagSupport.unExposeVariables(LoopTagSupport.java:587)
    at javax.servlet.jsp.jstl.core.LoopTagSupport.doFinally(LoopTagSupport.java:323)
    at jsp_servlet._jsp.__searchsuccess._jsp__tag3(__searchsuccess.java:294)
    at jsp_servlet._jsp.__searchsuccess._jspService(__searchsuccess.java:137)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)

It works fine on Tomcat Server but when I deploy it on Weblogic(9.2) server it gives the error. My classpath entries are:

<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
    <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-fileupload-1.1.1.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-io-1.2.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-logging-1.1.1.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/hibernate-validator-4.0.2.GA.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/log4j-1.2.14.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/slf4j-api-1.5.6.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/slf4j-log4j12-1.5.6.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-asm-3.0.3.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-beans-3.0.3.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-context-3.0.3.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-core-3.0.3.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-expression-3.0.3.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-web-3.0.3.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/spring-webmvc-3.0.3.RELEASE.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/validation-api-1.0.0.GA.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/log4j-1.2.9.jar"/>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/servlet-2.3.jar"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre6">
        <attributes>
            <attribute name="owner.project.facets" value="jst.java"/>
        </attributes>
    </classpathentry>
    <classpathentry kind="lib" path="WebContent/WEB-INF/lib/jstl-1.2.jar"/>
    <classpathentry kind="output" path="WebContent/WEB-INF/classes"/>

Update: I have removed the jstl-1.2.jar and now I get a compilation error:

searchsuccess.jsp:1:5: No tag library could be found with this URI. Possible causes could be that the URI is incorrect, or that there were errors during pa
rsing of the .tld file.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    ^----^
searchsuccess.jsp:1:5: No tag library could be found with this URI. Possible causes could be that the URI is incorrect, or that there were errors during pa
rsing of the .tld file.
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
    ^----^

        at weblogic.servlet.jsp.JavelinxJSPStub.compilePage(JavelinxJSPStub.java:298)
        at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:200)
        at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:164)
        at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:235)
        at weblogic.servlet.internal.ServletStubImpl.onAddToMapException(ServletStubImpl.java:394)
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
GOK
  • 2,338
  • 6
  • 34
  • 63
  • Also, i saw somewhere.... not to use jsp-api.jar but it is not the case for me as i am not having any jsp-api.jar in my web app.. :P – GOK Sep 01 '11 at 18:25

2 Answers2

1

As per the stacktrace,

java.lang.NoSuchMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext;
    at javax.servlet.jsp.jstl.core.LoopTagSupport.unExposeVariables(LoopTagSupport.java:587)

the JSTL <c:forEach> tag is expecting the method PageContext#getELContext(). This method was introduced in JSP 2.1. This exception thus suggests that you are using JSTL 1.2, while your container doesn't support JSP 2.1 or that you have littered your runtime classpath with servletcontainer specific JSP libraries of a container which doesn't support JSP 2.1. The runtime classpath covers among others the webapp's /WEB-INF/lib folder and Java's JRE/lib and JRE/lib/ext folders .

You should never put servletcontainer specific libraries in those folders, such as jsp-api.jar, servlet-api.jar, el-api.jar, j2ee.jar, javaee.jar, etc..etc.. Those files which you usually see in /lib folder of the servletcontainer itself. E.g. Tomcat/lib. It makes your webapp unportable to the target servletcontainer. The target servletcontainer where you're running this webapp has those libraries already. If you did this to overcome compilation errors on JSP/Servlet packages, then you should have solved it differently. See also How do I import the javax.servlet API in my Eclipse project?


Update: as per your update, you're using Weblogic 9.2 which is a Servlet 2.4 / JSP 2.0 container. It does not support JSP 2.1 / JSTL 1.2 at all. You need to remove the JSTL 1.2 library. If I am not mistaken, Weblogic ships with JSTL 1.1 already. Otherwise you need to include it in the classpath (the /WEB-INF/lib folder) yourself. You can find a JSTL 1.1 download link in our JSTL wiki page.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • java.lang.NoSuchMethodError: javax.servlet.jsp.PageContext.getELContext()Ljavax/el/ELContext; at javax.servlet.jsp.jstl.core.LoopTagSupport.unExposeVariables(LoopTagSupport.java:587) at javax.servlet.jsp.jstl.core.LoopTagSupport.doFinally(LoopTagSupport.java:323) at jsp_servlet._jsp.__searchsuccess._jsp__tag3(__searchsuccess.java:294) at jsp_servlet._jsp.__searchsuccess._jspService(__searchsuccess.java:137) at weblogic.servlet.jsp.JspBase.service(JspBase.java:34) – GOK Sep 02 '11 at 05:04
  • hey man its gud one which u put.... please have a look i have edited the post.. hope you are clear and get the picture;; – GOK Sep 02 '11 at 05:18
  • Remove `jstl-1.2.jar`. Weblogic already ships with JSTL 1.1. Weblogic 9.2 only supports Servlet 2.4 / JSP 2.0. JSTL 1.2 requires Servlet 2.5 / JSP 2.1. Hence this exception. – BalusC Sep 02 '11 at 12:05
  • I am getting an compilation error in my jsp on this line searchsuccess.jsp:1:5: No tag library could be found with this URI. Possible causes could be that the URI is incorrect, or that there were errors during parsing of the .tld file. <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> – GOK Sep 02 '11 at 14:56
  • Then Weblogic apparently didn't ship with JSTL 1.1 or you have littered the classpath with loose TLD files from JSTL 1.2. In any case, you need at highest JSTL 1.1. If Weblogic really doesn't ship with it (which would surprise me), then you could try providing it yourself. You can find a JSTL 1.1. download link in our JSTL wiki page http://stackoverflow.com/tags/jstl/info It consists of two JAR files `jstl.jar` and `standard.jar`. – BalusC Sep 02 '11 at 15:00
  • So i will put these jstl1.1 jars in my classpath.... ALso, i havent done anything with my classpath for loose tlds.. its pasted at the post.. u can check!!! – GOK Sep 02 '11 at 15:06
  • Hey @BalusC...thanks man...it worked i deleted the jstl1.2 jar and downloaded the jstl 1.1.jar and it contained two JAR files jstl.jar and standard.jar; made build and deployed...Hooray..no exception & works fine... – GOK Sep 02 '11 at 18:31
0

Do you have a el-api.jar in your webapp?

Please see the following post:

http://www.coderanch.com/t/526731/JSP/java/java-lang-NoSuchMethodError-javax-servlet

-Kaj :)

Kaj Hejer
  • 955
  • 4
  • 18
  • The presence of the `el-api.jar` alone can not have resulted in this particular exception. Even more, the `el-api.jar` doesn't exist prior JSP 2.1. In JSP 2.0, it was shipped as part of `jsp-api.jar` (at least, in Tomcat). EL was extracted from JSP as per JSP 2.1. See also http://stackoverflow.com/questions/4812755/difference-between-jsp-el-jsf-el-and-unified-el/4812883#4812883 for a bit of EL history. – BalusC Sep 01 '11 at 18:54