Solved

can't run jstl in jsp

Posted on 2004-10-27
692 Views
Last Modified: 2013-11-24
I am trying to use jstl in my jsp page but its giving hte following error.

 org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application


i have copied jstl.jar in my webapps lib directory.
Here is my jsp file
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<body>
   <table>
     <c:forEach var="movie" items="${movieList}" >             
     <tr>       
        <td>${movie}</td>      
    </tr>
  <c:forEach>
   </table></body></html>

here is my servlet

package com.example.ams;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class JstlServlet extends HttpServlet {

      public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {

              String[] movieList = {"Amelie", "Return of the King", "Mean Girls"};
          request.setAttribute("movieList", movieList);
              RequestDispatcher rd = request.getRequestDispatcher("jsp/jstlJsp.jsp");
              rd.forward(request, response);
      }
}

thanks
0
Question by:angela_smith
    44 Comments
     
    LVL 86

    Expert Comment

    by:CEHJ
    Do you have the following in your web.xml?


       <taglib>
         <taglib-uri>http://java.sun.com/jsp/jstl/core</taglib-uri>
    .....etc

    ?    
    0
     

    Author Comment

    by:angela_smith
    Thanks
    No it wasn't there.
    Now i have done this
        <taglib>
           <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
           <taglib-location>/WEB-INF/lib/c.tld</taglib-location>
        </taglib>

    Still getting the same error. I am not sure about c.tld
    Found it on googling.
    What do i need to correct.
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    >>I am not sure about c.tld

    Should be core.tld

    You should read up on the correct configuration ...
    0
     
    LVL 21

    Expert Comment

    by:MogalManic
    For every taglib you use you need to add the following to your configureation
      1)  Add to the Web XML the TLD definition
           E.G:
        <taglib>
            <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
            <taglib-location>c.tld</taglib-location>
        </taglib>
       2) Add the c.tld file from the JSTL distribution to your WEB-INF directory
    0
     

    Author Comment

    by:angela_smith
    >> Add the c.tld file from the JSTL distribution to your WEB-INF directory
    I have added the whole jstl.jar to WEB-INF/lib directory
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    >>Still getting the same error.

    Actually that seems right. Did you recycle the container?
    0
     

    Author Comment

    by:angela_smith
    there is no tld file in the jstl.jar file.
    Neither with c.tld nor core.tld
    0
     

    Author Comment

    by:angela_smith
    >>Did you recycle the container?
    Yes done that
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    Where did you get the taglibs from? You should have an archive called something like *standard* that contains the tld files
    0
     

    Author Comment

    by:angela_smith
    >>Where did you get the taglibs from? You should have an archive called something like *standard* that contains the tld files

    That seems to be problem. I copied standard.jar to the lib and nor i am getting this.

    javax.servlet.jsp.tagext.TagAttributeInfo.<init>(Ljava/lang/String;ZLjava/lang/String;ZZ)V
    0
     

    Author Comment

    by:angela_smith
    javax.servlet.ServletException: javax.servlet.jsp.tagext.TagAttributeInfo.<init>(Ljava/lang/String;ZLjava/lang/String;ZZ)V
    0
     

    Author Comment

    by:angela_smith
    java.lang.NoSuchMethodError: javax.servlet.jsp.tagext.TagAttributeInfo.<init>(Ljava/lang/String;ZLjava/lang/String;ZZ)V
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    0
     

    Author Comment

    by:angela_smith
    Same error.
    I copied only jstl.jar and standard.jar in lib and redeployed.
    Do i need to copy anything else also?
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    You should read the docs!
    0
     
    LVL 21

    Expert Comment

    by:MogalManic
    Did you put the TLD's in the WEB_INF directory?
    0
     

    Author Comment

    by:angela_smith
    >>Did you put the TLD's in the WEB_INF directory?
    put both the jar files in WEB-INF/lib  
    (standard.jar and jstl.jar)
    0
     
    LVL 21

    Expert Comment

    by:MogalManic
    The JARS need to be in the path AND the c.tld file needs to be in the WEB-INF directory.
    0
     

    Author Comment

    by:angela_smith
    c.tld file is in standard.jar
    0
     

    Author Comment

    by:angela_smith
    c.tld file is in standard.jar which is in WIB-INF lib directory
    0
     

    Author Comment

    by:angela_smith
    I dont know what could be the reason.

    None of the build in JSP 2.0 examples under jsp-examples directory are running. But JSP 1.2 examples are running fine.
    please help me, what could be the problem?
    0
     

    Author Comment

    by:angela_smith
    This is what i got when i tried to execute one the inbuild JSP2.0 examples under jsp-examples

    java.lang.NoSuchMethodError: javax.servlet.jsp.PageContext.getVariableResolver()Ljavax/servlet/jsp/el/VariableResolver;
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    >>This is what i got when i tried to execute one the inbuild JSP2.0 examples under jsp-examples

    Do your libraries support jsp2?
    0
     

    Author Comment

    by:angela_smith
    >>Do your libraries support jsp2
    yes tomcat 5 support jsp2
    0
     

    Author Comment

    by:angela_smith
    Tomcat 5 has inbuild jstl examples under jsp-examples. Had it been an earlier version there wouldn't have been inbuild jstl examples. I tried making my own jsp pages using jstl but there is the same error as there is while executing inbuild jstl examples
    0
     

    Author Comment

    by:angela_smith
    This is the exact error I am getting

    javax.servlet.ServletException: Error instantiating servlet class org.apache.jsp.jsp2.tagfiles.hello_jsp
          org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
          org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
          org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
          org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
          org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
          org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
          org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
          java.lang.Thread.run(Thread.java:536)


    root cause

    java.lang.VerifyError: (class: org/apache/jsp/jsp2/tagfiles/hello_jsp, method: _jspx_meth_tags_helloWorld_0 signature: (Ljavax/servlet/jsp/PageContext;)Z) Incompatible argument to function
          java.lang.Class.getDeclaredConstructors0(Native Method)
          java.lang.Class.privateGetDeclaredConstructors(Class.java:1590)
          java.lang.Class.getConstructor0(Class.java:1762)
          java.lang.Class.newInstance0(Class.java:276)
          java.lang.Class.newInstance(Class.java:259)
          org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
          org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
          org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
          org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
          org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
          org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
          org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
          java.lang.Thread.run(Thread.java:536)


    note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.

    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    That looks like some kind of binary incompatibility. Make sure all libraries are symmetrical. i.e. don't compile against different libraries than you'll be running against and make sure you have the latest versions of libraries. The safest thing to do is to compile against Tomcat's own jars
    0
     

    Author Comment

    by:angela_smith
    >>The safest thing to do is to compile against Tomcat's own jars

    Thats exactly what I am doing. This error comes while executing Tomcats build in examples at
     http:// localhost:8080/jsp-examples
    and for executing its own examples Tomcat uses its own libraries that comes with tomcat 5. i have not put in any jar file myself
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    I thought earlier you'd been placing tag lib binaries in Tomcat's classpath? (That was the whole thrust of the earlier part of this question)

    When you've double-checked the binaries, try deleting the compiled servlets (from the JSP) and recycle the container

    0
     

    Author Comment

    by:angela_smith
    >> thought earlier you'd been placing tag lib binaries in Tomcat's classpath? (That was the whole thrust of the earlier part of this question)

    yes CEHJ u r absolutely right, that was the whole thrust of the earlier ques. But when it didn't work i tried the inbuild examples under jsp-examples to see if they work. But even they gave the same error. So, if the inbuild examples under jsp-exampels start working i guess there woudn't be much problem in making my own jsp's do the same. For inbuild examples all jar files are already in the classpath.
    So when I go to this url http://localhost:8080/jsp-examples  
    Tomcat shows a page in which there are a lot of examples under the head JSP2.0 and JSP1.2. Every example has 2 links "execute" and "source". Clicking on source cause no problem. Clicking on execute of jsp1.2 examples causes no problem. But clicking in execute of jsp2.0 gives the above weird error. Tomcat5.0 is jsp2.0 compliant server (that's why they have those inbuild examples)

    >>When you've double-checked the binaries, try deleting the compiled servlets (from the JSP) and recycle the container
    I have uninstalled and reinstalled tomcat atleast 20 times. Also did on another machine (my home PC) . But same problem is everwhere.

    Infact I googled a lot and saw this problem in quite a few question in various forums but none of  it had any answer that solved the problem
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    >>
    So, if the inbuild examples under jsp-exampels start working i guess there woudn't be much problem in making my own jsp's do the same
    >>

    That's a sensible approach.

    >>
    this problem in quite a few question in various forums but none of  it had any answer that solved the problem
    >>

    Have you got the very latest version of Tomcat?
    0
     

    Author Comment

    by:angela_smith
    >>Have you got the very latest version of Tomcat?

    Yes, tried even the beta version
    0
     

    Author Comment

    by:angela_smith
    these are teh versions i have tried

    jakarta-tomcat-5.0.28
    jakarta-tomcat-5.0.29
    jakarta-tomcat-5.5.3

    There is no version after this.
    0
     

    Author Comment

    by:angela_smith
    2nd and 3rd above are beta versions.
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    The only thing i can suggest is *lowering* the version until it comes out right ;-)
    0
     

    Author Comment

    by:angela_smith
    A lower version that jakarta-tomcat-5.0.28 would be tomcat 4.1.x which i think is not jsp2 compliant
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    Yes, i thought that might happen. I can't believe, btw, that all 3 of those versions you mention are 'genuinely' defective, so you must inspect your environment *very* closely for binaries knocking around from earlier attempts. Make sure you empty everything before installing a new version, even scouring your system for stale jars. Don't think of installing over an old one
    0
     

    Author Comment

    by:angela_smith
    >>Make sure you empty everything before installing a new version, even scouring your system for stale jars. Don't think of installing over an old one
    I emptied everything. Never deleted but uninstalled and then even used system mechanic to clear registry entries and get rid of useless files. Installed tomcat on different drives with  different name. i have done it all. The only option i can think of now is format my hard drive and makea clean install
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    >>The only option i can think of now is format my hard drive and makea clean install

    That would be over-the-top i think ;-) I think there must be something you've missed. Uninstall again and then post a listing of all jars on the drive
    0
     

    Author Comment

    by:angela_smith
    The have jbuilder8 installed in one of the drives (although I am not using jbuilder for this) and java_home is set to the jdk inside the jbuilder.
    Could that possibly be the problem ?
    0
     
    LVL 86

    Accepted Solution

    by:
    >>Could that possibly be the problem ?

    Yes it could. JBuilder often has pretty old binaries
    0
     
    LVL 8

    Expert Comment

    by:thomas908
    CEHJ  is absolutely right.
    Uninstall JBUilder and clear all ur classapaths. Even then the problem is not solved then delete ur existing jar files and make a fresh install for jdk and tomcat.
    With jsp2 u don't even need to make any entry in web.xml, so a proper installation will do it for u.
    0
     

    Author Comment

    by:angela_smith
    Thanks CEHJ , its working now.
    I uninstalled everything. cleared all the classpaths and deleted all the jar files in my system and made a clean install. Its working now.
    It was so nice of u CEHJ  to work it up all along.
    thanks again
    0
     
    LVL 86

    Expert Comment

    by:CEHJ
    No problem ;-)
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Suggested Solutions

    For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now