Link to home
Start Free TrialLog in
Avatar of angela_smith
angela_smith

asked on

can't run jstl in jsp

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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Do you have the following in your web.xml?


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

?    
Avatar of angela_smith
angela_smith

ASKER

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.
>>I am not sure about c.tld

Should be core.tld

You should read up on the correct configuration ...
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
>> 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
>>Still getting the same error.

Actually that seems right. Did you recycle the container?
there is no tld file in the jstl.jar file.
Neither with c.tld nor core.tld
>>Did you recycle the container?
Yes done that
Where did you get the taglibs from? You should have an archive called something like *standard* that contains the tld files
>>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
javax.servlet.ServletException: javax.servlet.jsp.tagext.TagAttributeInfo.<init>(Ljava/lang/String;ZLjava/lang/String;ZZ)V
java.lang.NoSuchMethodError: javax.servlet.jsp.tagext.TagAttributeInfo.<init>(Ljava/lang/String;ZLjava/lang/String;ZZ)V
Same error.
I copied only jstl.jar and standard.jar in lib and redeployed.
Do i need to copy anything else also?
You should read the docs!
Did you put the TLD's in the WEB_INF directory?
>>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)
The JARS need to be in the path AND the c.tld file needs to be in the WEB-INF directory.
c.tld file is in standard.jar
c.tld file is in standard.jar which is in WIB-INF lib directory
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?
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;
>>This is what i got when i tried to execute one the inbuild JSP2.0 examples under jsp-examples

Do your libraries support jsp2?
>>Do your libraries support jsp2
yes tomcat 5 support jsp2
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
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.

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

>> 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
>>
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?
>>Have you got the very latest version of Tomcat?

Yes, tried even the beta version
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.
2nd and 3rd above are beta versions.
The only thing i can suggest is *lowering* the version until it comes out right ;-)
A lower version that jakarta-tomcat-5.0.28 would be tomcat 4.1.x which i think is not jsp2 compliant
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
>>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
>>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
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 ?
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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
No problem ;-)