2011-09-01 57 views
2

我有一個彈簧控制器,我在其中返回一個名爲「model」的Map;模型包含一些值,但重要的還包含一個ArrayList。現在我將這個Map返回給我的JSP,而在我的JSP中使用JSTL來獲取ArrayList它會拋出錯誤。使用JSTL訪問從Spring Controller到JSP的映射時出錯

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

產生的錯誤是:

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) 

它的工作原理Tomcat服務器上的罰款,但是當我Weblogic上部署它(9.2)服務器它給人的錯誤。我的類路徑條目:

<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"/> 

更新:我已刪除了JSTL-1.2.jar現在我得到一個編譯錯誤:

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) 
+0

另外,我看到的地方....不使用JSP-api.jar文件,但它不是的情況下我,因爲我沒有任何jsp-api.jar在我的web應用程序..:P – GOK

回答

1

按堆棧跟蹤,

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

JSTL <c:forEach>標籤期待的方法PageContext#getELContext()。這個方法在JSP 2.1中引入。因此,此異常表明您正在使用JSTL 1.2,而您的容器不支持JSP 2.1,或者您已將運行時類路徑與不支持JSP 2.1的容器的servlet容器特定的JSP庫混雜在一起。運行時類路徑包括webapp的/WEB-INF/lib文件夾和Java的JRE/libJRE/lib/ext文件夾。

你應該從未放servletcontainer在這些文件夾中的特定庫,如jsp-api.jarservlet-api.jarel-api.jarj2ee.jarjavaee.jar,etc..etc ..這些文件,你通常在servletcontainer本身的/lib文件夾中看到。例如。 Tomcat/lib。它使你的webapp不可移植到目標servlet容器。您正在運行此Web應用程序的目標servletcontainer有這些庫已經。如果你這樣做是爲了克服JSP/Servlet包的編譯錯誤,那麼你應該以不同的方式解決它。另請參見How do I import the javax.servlet API in my Eclipse project?


更新:根據您的更新,你使用的Weblogic 9.2這是一個Servlet 2.4/JSP 2.0容器。它根本不支持JSP 2.1/JSTL 1.2。您需要刪除JSTL 1.2庫。如果我沒有弄錯,Weblogic已經提供了JSTL 1.1。否則,您需要自己將其包含在類路徑(/WEB-INF/lib文件夾)中。您可以在our JSTL wiki page中找到JSTL 1.1下載鏈接。

+0

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

+0

hey man its gud one你把它放在....請看看我編輯過的帖子..希望你清楚,並得到圖片;; – GOK

+0

刪除'jstl-1.2.jar'。 Weblogic已經與JSTL 1.1一起提供。 Weblogic 9.2僅支持Servlet 2.4/JSP 2.0。 JSTL 1.2需要Servlet 2.5/JSP 2.1。因此這個例外。 – BalusC

0

你的webapp中是否有el-api.jar?

請看下面的帖子:

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

-Kaj :)

+0

單獨存在'el-api.jar'不能導致這種特殊的異常。更甚者,'el-api.jar'在JSP 2.1之前並不存在。在JSP 2.0中,它是作爲'jsp-api.jar'的一部分發布的(至少在Tomcat中)。 EL根據JSP 2.1從JSP中提取。查看http://stackoverflow.com/questions/4812755/difference-between-jsp-el-jsf-el-and-unified-el/4812883#4812883瞭解EL歷史。 – BalusC