GeeCON Prague 2014*
The moose likes JSP and the fly likes JSTL Function import error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "JSTL Function import error" Watch "JSTL Function import error" New topic
Author

JSTL Function import error

Lisa Modglin
Ranch Hand

Joined: Oct 28, 2003
Posts: 46
I'm using several of the JSTL libraries with no problem, but when I went to add the functions library, I get an error regarding the location of the jar file. I had to remove the /jsp/ from the declaration to get sql, core and fmt to work. I tried functions with and without the /jsp/ in the declaration and neither way works. Any suggestions?

Declarations:
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="jsp_sql" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="jsp_core" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jstl/functions" prefix="fn" %>

Error:
org.apache.jasper.JasperException: The absolute uri: http://java.sun.com/jstl/functions cannot be resolved in either web.xml or the jar files deployed with this application
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:50)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:411)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:118)
org.apache.jasper.compiler.TagLibraryInfoImpl.generateTLDLocation(TagLibraryInfoImpl.java:316)
org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:147)
org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:418)
org.apache.jasper.compiler.Parser.parseDirective(Parser.java:483)
org.apache.jasper.compiler.Parser.parseElements(Parser.java:1539)
org.apache.jasper.compiler.Parser.parse(Parser.java:126)
org.apache.jasper.compiler.ParserController.doParse(ParserController.java:220)
org.apache.jasper.compiler.ParserController.parse(ParserController.java:101)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:203)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

As per forum instructions, please include information regardin what version of the JSTL you are using and what container version you are using.

Since you are using functions, I'll assume JSTL 1.1, in which case removing the "jsp" prefix from the URIs of any of the JSTL libraries is the wrong thing to be doing.

Since the function library was introduced in JSTL 1.1, the URI "http://java.sun.com/jstl/function" has never, and will never, be valid.

The correct URI is http://java.sun.com/jsp/jstl/functions
[ June 07, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Lisa Modglin
Ranch Hand

Joined: Oct 28, 2003
Posts: 46
I'm not sure what version I'm using. I was somewhat confused on the download page. Myabe I'm using the older version and that would explain why the function won't work. :-) Thanks, I'll check that out.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

What version you should be using will be determined by the version of Tomcat that you are using. So what is it?
[ June 07, 2006: Message edited by: Bear Bibeault ]
Lisa Modglin
Ranch Hand

Joined: Oct 28, 2003
Posts: 46
Tomcat version is 5.0.28. But, I think I took the JAR files from the JSTL download from the jakarta-taglibs/standard-1.0 directory. I'm going to try replacing them with the jar files in the jakarta-taglibs/standard/lib directory. I'll let you know if that doesn't work and maybe you can make a suggestion.
Lisa Modglin
Ranch Hand

Joined: Oct 28, 2003
Posts: 46
I did that and now it will compile using the /jsp/ in the dec. I tried adding /jsp/ to the other decs and I'm getting errors that I didn't get previously. Did they change their implementation of some of the functions?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

They should all be using the same format. If you are getting errors, something is wrong in the set up.

What is your setup, and what errors are you getting?
Lisa Modglin
Ranch Hand

Joined: Oct 28, 2003
Posts: 46
I had to leave early yesterday. I'm just getting back to it. A question, I've been developing JSPs using Servlets and Java classes for several years. I've never used JSTLs. My boss has developed his own taglibs and I implement some of them. I stumbled upon the JSTLs while looking for authentication information. Anyway, I don't see what I'm gaining by using them opposed to using a servlet. What advantages do you find in using JSTL, if any?

I've included the first error I receive as well as the code that either causes the error or that at least contains the variable that it is complaining about. I'm not sure how to answer your question when you ask about my setup. Sorry!

Error:
java.lang.NumberFormatException: For input string: "${noOfRows}"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
java.lang.Integer.parseInt(Integer.java:447)
java.lang.Integer.valueOf(Integer.java:553)
org.apache.jasper.compiler.JspUtil.coerceToInt(JspUtil.java:752)
org.apache.jasper.compiler.Generator$GenerateVisitor.convertString(Generator.java:2916)
org.apache.jasper.compiler.Generator$GenerateVisitor.evaluateAttribute(Generator.java:2719)
org.apache.jasper.compiler.Generator$GenerateVisitor.generateSetters(Generator.java:2825)
org.apache.jasper.compiler.Generator$GenerateVisitor.generateCustomStart(Generator.java:2158)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1669)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1441)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1689)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1441)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3272)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:244)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:470)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:451)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:511)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:295)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


Code:
<jsp_core:set var="noOfRows" value="5" />

<jsp_sql:query
var="students"
dataSource="${ds}"
scope="session"
maxRows="${noOfRows}"
startRow="${begin}">

SELECT a.StudentID, a.StuLName, a.StuFName, a.StuUsername, a.Created, a.Inactive, b.Reason, b.UserId, InactiveDate, c.Fname, c.Lname FROM Student a LEFT OUTER JOIN Inactive b ON a.StudentID = b.StudentID LEFT OUTER JOIN Users c ON b.UserId = c.UserId WHERE UPPER( StuLName ) LIKE ? ORDER BY a.StuLName
<jsp_sql:param value="${param.letter}%" />
</jsp_sql:query>
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Originally posted by Lisa Modglin:
Anyway, I don't see what I'm gaining by using them opposed to using a servlet. What advantages do you find in using JSTL, if any?


That makes no sense to me. The JSTL is a set of standard tags for use in JSP pages. How does that compare to servlets? Apples and oranges.


I've included the first error I receive as well as the code


Before diagnosing any errors, your setup needs to get straightened out. If you are using the 'jsp' prefix on some taglib URIs and not on others, you are mixing tags from different version levels and that will cause no end of problems.

I'm not sure how to answer your question when you ask about my setup.


How did you set up the JSTL? Where did you get the files from? Where did you put them? Did you put anything in the web.xml? What are the taglib directives that you are placing in your JSP?
[ June 08, 2006: Message edited by: Bear Bibeault ]
Lisa Modglin
Ranch Hand

Joined: Oct 28, 2003
Posts: 46
Servlets vs. JSTL. Typically, we use Java classes to retrieve data from the database, create an object and then the JSP page retrieves the pieces of information for display on the Web page from the object. I'm using the JSTLs to do the same thing and trying to determine if there is an advantage in using them. Sorry you don't see the relevance. Even though you may not be comparing apples to apples, I'm comparing two different ways to come to the same result and am trying to determine which is better.

As far as my setup, I downloaded the JSTLs from Jakarta's site: http://people.apache.org/builds/jakarta-taglibs/nightly/ and downloaded: jakarta-taglibs-20060603.zip I unzipped the file and installed jstl.jar and standard.jar (jakarta-taglibs/standard/lib/) to L:\tomcat-5.0.28-stuservice-dev\shared\lib. The taglib directives are:

<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="jsp_sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="jsp_core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

I don't think I put anything in my web.xml file except the database info:

<context-param>
<param-name>dbURL</param-name>
<param-value>jdbc:JSQLConnect://localhost/database=someDatabase</param-value>
</context-param>

<context-param>
<param-name>dbUsername</param-name>
<param-value>someUsername</param-value>
</context-param>

<context-param>
<param-name>dbPassword</param-name>
<param-value>somePassword</param-value>
</context-param>

Before, when using the older jar files, I did not receive any errors. Thanks for your assistance.

Lisa
Lisa Modglin
Ranch Hand

Joined: Oct 28, 2003
Posts: 46
I was testing and noticed that when I remove everything except:

<jsp_core:set var="noOfRows" value="5" />

<jsp_coreut value="${noOfRows}" />

${noOfRows} prints to the JSP page. Has there been a change in the way you reference the expressions. Can't remember what the technical term is for ${...

Lisa
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Originally posted by Lisa Modglin:
Servlets vs. JSTL.


Still don't see any "versus" here. Typically, a servlet controller will obtain data and forward to a JSP placing appropriate data on the request as scoped variables. Whether the JSTL is used on the JSP or not is moot.


As far as my setup, I downloaded the JSTLs from Jakarta's site:


Down-loading the nightly builds isn't a great idea. Grab the stable version here.

The taglib directives are:


Looks correct, although I'd recommend using the conventional prefixes rather than making up your own.

Also, you aren't really using the sql tags, are you?

I don't think I put anything in my web.xml file


Good. Don't. A lot of people make this mistake.

Looks like your setup is ok except for the jars.

Let me know when you've tried this again with the stable versions and I'll see what I can think of regarding your NFE.
[ June 08, 2006: Message edited by: Bear Bibeault ]
Lisa Modglin
Ranch Hand

Joined: Oct 28, 2003
Posts: 46
Okay,

I downloaded and installed the new jar files and then restarted Tomcat. I changed the prefixes to suggested. Still having the same problem. I don't know if you read that extra smaller post, but if I hard code the numbers in, it gets past the first error. Then I tried printing the value of the variable to the screen and it's as if it doesn't see the variable as a variable but as a string.

Why shouldn't I use the sql tags?

Lisa
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66



This will indeed set the value of xyz to the string "5". All static attributes of actions are strings as per the JSP specification (nothing to so with JSTL, per se).

If you want it to be numeric, use:



where the attribute is dynamic and set to the evaluation of the specified EL experssion.
[ June 08, 2006: Message edited by: Bear Bibeault ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Originally posted by Lisa Modglin:

Why shouldn't I use the sql tags?


Becasue performing SQL operations on a JSP page is an egregious violation of the accepted best practice of Separation of Concerns.

Even the creators of the sql tags say (paraphrased): well, they're there if you need them, but it's not a good idea in real code.
Lisa Modglin
Ranch Hand

Joined: Oct 28, 2003
Posts: 46
See, that answers my question about whether or not using the JSTLs for what we are doing is better or not than how we are going about it now. I read how to use them in the O'Reilly JavaServer Pages book. I didn't notice anything in there about them not being best practices, but perhaps I overlooked it. I was using the Second Edition and not the newest edition. The sole purpose of my exercise was for populating from a database using the tags. I'll just revert to the way we've been doing things. Thanks!
Lisa Modglin
Ranch Hand

Joined: Oct 28, 2003
Posts: 46
Thanks for your explanations. I think the problem comes when I USE the variable ${noOfRows}. When I run the following code, I think 5 should print to the screen, but instead ${noOfRows} is printing to the screen.

I won't be using this code anyway, if it is not best practices to use the sql tags.

<%@ page language="java" contentType="text/html" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<head>
</head>
<body>

<core:set var="noOfRows" value="${5}" />
<coreut value="${noOfRows}" />

</body>
</html>
Lisa Modglin
Ranch Hand

Joined: Oct 28, 2003
Posts: 46
I hear the word best practices nearly every day. What I know about best practices comes from my supervisor. So, please tell me where I can read up on the "Best Practices".

Thanks again for your help.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Looks like the EL may not be enabled for your application.

To test, create a page that has the following body:



When you see 7, you'll know you're ok.

The most likely culprit is your web.xml. Is it declared using the 2.3 DOCTYPE or the 2.4 Schema? It must be the latter.

See the JSP FAQ for details.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Originally posted by Lisa Modglin:
I hear the word best practices nearly every day. What I know about best practices comes from my supervisor. So, please tell me where I can read up on the "Best Practices".


With regards to web application structure, search for the terms "MVC" and "Model 2".
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

http://faq.javaranch.com/view?ElOrJstlNotWorkingAsExpected
Lisa Modglin
Ranch Hand

Joined: Oct 28, 2003
Posts: 46
Here's is my JSP:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="core" %>

<html>
<head>
<title>Untitled</title>
</head>

<body>
${3 + 4}<br />
1 + 2 + 3 = <coreut value="${1 + 2 + 3}" /><br />



</body>
</html>


Here is the output:

${3 + 4}
1 + 2 + 3 = 6

And, my web.xml doctype:
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Your web.xml is declaring your app as a Servlets 2.2 web app! That's two revs out of date.

If you are using Tomcat 5, you need to update that the Servlets 2.4 schema as outline in the link I posted.

And this:

<%@ taglib uri="http://java.sun.com/jstl/core" prefix="core" %>


is the wrong URI.
[ June 08, 2006: Message edited by: Bear Bibeault ]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
Yep, there's your problem in web.xml

Basically with Tomcat 5, unless you use the Servlet2.4/JSP2.0 declaration in the web.xml, it will disable EL expressions in your page. They did this for backwards compatibility so as not to break existing websites.

Solution is in the FAQ:
Change your DTD in the web.xml for what you find at this link:
http://faq.javaranch.com/view?ServletsWebXml


On why JSTL is useful - I mainly use it on my page for looping/conditional statements and for displaying values. I find it much more convenient for displaying things on the page than scriptlet expressions were.

You can do some basic manipulation of variables with JSTL/EL, but it is not a fully fledged programming language. It is mainly intended to help with displaying JSP data, not calculating/retrieving it. Use it like that, and you should be able to eliminate 99.9% of scriptlet code from your JSP pages.

Cheers,
evnafets
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Originally posted by Stefan Evans:
and you should be able to eliminate 99.9% of scriptlet code from your JSP pages.


What he said... except you can easily achieve 100% script-free pages.
Lisa Modglin
Ranch Hand

Joined: Oct 28, 2003
Posts: 46
I have corrected the schema/doctype error. We had not realized that with Tomcat 5, they changed from DTDs to Schemas. That caused some other problems in my web.xml, but they are also corrected. I still have a problem with my page. Even though I may not use it (due to the sql tags), I'm bound and determined to get it working.

Now ${3+3} produces 6, but 1 + 2 + 3 = <coreut value="${1 + 2 + 3}" /><br /> produces an error: "According to TLD or attribute directive in tag file, attribute value does not accept any expressions."

I also tried:

<core:set value="test" var="test" />
<coreut value="${test}" />

with the same error. How do you reference a variable with JSTL 1.1?

Lisa
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Are you sure that you are using the JSTL 1.1 URI for the core tags? That error message is the classic error that occurs when trying to use the JSTL 1.0 with a JSP 2.0 container.
[ June 09, 2006: Message edited by: Bear Bibeault ]
Lisa Modglin
Ranch Hand

Joined: Oct 28, 2003
Posts: 46
I downloaded from this link by clicking on 1.1.2.zip at http://jakarta.apache.org/site/downloads/downloads_taglibs-standard.cgi.

I put jstl.jar and standard.jar, both dated 10/25/2004 from jakarta-taglibs-standard-1.1.2/lib, in L:\tomcat-5.0.28-stuservice-dev\shared\lib. I checked in the common directory to be sure I didn't have an older version lurking somewhere and I don't.

I just redownloaded and installed them again. I even did a search on my entire drive to see if there was another version of jstl.jar.

From my web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

My version of Tomcat:
L:\tomcat-5.0.28-stuservice-dev

Should I throw my hands up and declare defeat? I don't like to not figure something out, but it might be time to move on. Thank goodness I'm not swamped right now.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

You listed everything but what I asked for. Are you using the correct URI for the JSTL 1.1?
Lisa Modglin
Ranch Hand

Joined: Oct 28, 2003
Posts: 46
Oops:

I started a test page with very little code and that page had the old URI. Crud! Now the error on my original page has to do with the way I'm using one of the FN functions. So, I think I'm past all of the setup errors and can move on.

Thanks for all of your help getting the setup correct!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Whew! Glad that's over with! Set up is usually a breeze...
 
GeeCON Prague 2014
 
subject: JSTL Function import error