• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't get first JSTL to work

 
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have JSTL set up in MyEclipse for the current project. When I "deploy" the project, MyEclipse copies the jstl.jar and standard.jar and all the .tld files to the Webapps folder.

However, when I try to run the code, the "$" don't expand to show me what's in the variables. Clearly, I've got something set up wrong.

Below, I have my source code, the URL I used in the browser, and the browser's output.

I would appreciate any help or suggestions why this isn't working.

Here's my test JSP page:

<%@ page language="java" import="java.util.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName()
+ ":" + request.getServerPort() + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'MyJsp.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">

<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

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

This is my JSP page.

<%
String s = "JSTL is cool.";
pageContext.setAttribute("name", s);
%>

Getting ready to do some JSTL ...
<br>
<c:if test ='$(not empty param.amount)'>

<c ut value='$(param.amount)' />
<c ut value='$(name)' />

</c:if>
Okay, here's the value of name...
<br>
<c ut value='$(name)' />


Here's the value of param.amount
<br>
<c ut value='$(param.amount)' />

</body>
</html>
======================================

URL line in browser: http://localhost/JSTLTest/MyJsp.jsp?amount=100

Here's the output with the above URL line:

This is my JSP page. Getting ready to do some JSTL ...
Okay, here's the value of name...
$(name) Here's the value of param.amount
$(param.amount)

===================================

Look forward to any replies or suggestions why this isn't working.

Thanks.

-- Mike
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<c:if test ='$(not empty param.amount)'>

replace the () (round braces) with {} (curly braces) in all instances of JSTL tags.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, thanks.

Now, when I replace the () with {}, I get the following error:

org.apache.jasper.JasperException: /MyJsp.jsp(38,0) According to TLD or attribute directive in tag file, attribute test does not accept any expressions

----

I'm using the 1.1 version of the JSTL.

Any ideas what's going on?

Thanks again!!!

-- Mike
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what about including the correct JSTL declaration in your JSP? Just noticed that's missing as well...
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm not sure what you mean.

If:

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

isn't correct, what am I missing?

Thanks.

-- Mike
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First try using double quotes, it may not matter.

Also try the following:



[Bear edit: consolidated multiple replies. Craig, please make corrections by editing your original reply rather than making multiple replies with corrections.]
[ April 12, 2005: Message edited by: Bear Bibeault ]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


If:

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

isn't correct, what am I missing?



That is the URI for the JSTL 1.0. You stated you are using JSTL 1.1. The URI for that would be:



You are using a JSP 2.0 capable container, right?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The JSTL 1.1 Specification is available here.

If you are writing JSTL you should have a copy on your desk (or desktop). The proper URI's are on page 2.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This has no effect.

"Core JSTL" uses single quotes.

I still get the same error.

Not sure what's going on with this error:

org.apache.jasper.JasperException: /MyJsp.jsp(38,0) According to TLD or attribute directive in tag file, attribute test does not accept any expressions

Thanks again in advance!!!

-- Mike
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem with my code was I needed a:

<%@ page isELIgnored="true" %>

at the top of the page.

The issues are these:

1) You are not allowed to use JSP scripting elements for "test". Ie the following is illegal:
<c:if test="<%= Math.random() < 0.5 %>">

2) You are using Tomcat 5 and a servlet 2.4 declaration in your web.xml, so the JSP 2.0 expression language is enabled.

3) The ${...} is interpreted by JSP 2 before JSTL gets a chance to get a crack at it.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

"Core JSTL" uses single quotes.



In any tag library you can use single or double quotes. It makes no difference.

If you are using JSP 2.0, you should be using JSTL 1.1 precisely because in JSP 2.0 it is the container that manages the EL evaluation rather than the JSTL itself.
 
Mike London
Bartender
Posts: 1971
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your reply.

I am using JSTL 1.1, but apparently still needed the

<%@ page isELIgnored="true" %> at the top of the JSP file or get the error I posted.

The single vs. double quotes comment I made was just that it didn't affect anything relative to my problem. So I agree with your comment there.

Thanks again.

-- M
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The question is, if you are using JSP 2.0 and JSTL 1.1, why are you using a scripting expression at all? You should be using the EL on the page, not disabling it.
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Excellent Mike thank you for posting your solution. I have the same setup and the exact same problem, the isELIgnored tags works a treat. Nice one.

cheers
Martin

Originally posted by Mike London:
The problem with my code was I needed a:

<%@ page isELIgnored="true" %>

at the top of the page.

The issues are these:

1) You are not allowed to use JSP scripting elements for "test". Ie the following is illegal:
<c:if test="<%= Math.random() < 0.5 %>">

2) You are using Tomcat 5 and a servlet 2.4 declaration in your web.xml, so the JSP 2.0 expression language is enabled.

3) The ${...} is interpreted by JSP 2 before JSTL gets a chance to get a crack at it.

 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No no no no NO!

You do NOT need: <%@ page isELIgnored="true" %>
You need to replace
this: <%@ taglib uri='http://java.sun.com/jstl/core' prefix='c'%>
with: <%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>


Mikes solution is WRONG! You should NOT be disabling EL evaluation on the page.
Ok, it does make it work, but there is a better approach.
USE THE CORRECT JSTL URI!!!

It is frustrating to me that
- there is an FAQ on this subject (that obviously noone reads)
- this question gets asked at least once every couple of days
- Despite the numerous correct answers given, people can still come up with the wrong solution, and then other people USE THAT INCORRECT SOLUTION!

(pant...pant...pant...)
Ok, I'm calm now..... really.

If you have a JSP1.2 container (Tomcat 4), use JSTL1.0: <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
If you have a JSP2.0 container (Tomcat 5), user JSTL1.1: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

Note the subtle difference with the addition of "/jsp" in there?
JSTL1.0 has to evaluate the expression itself, and so you can't use runtime expression values for that taglib.
JSTL1.1 expects the container to handle the expression - so it accepts runtime expressions.
[ August 01, 2006: Message edited by: Stefan Evans ]
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stefan Evans:
No no no no NO!



What he said.

Turning off the EL is putting a band-aid on chicken wire held up with bubble gum.

Fix the configuration problem, don't cobble together a patch for the symptoms.
[ August 01, 2006: Message edited by: Bear Bibeault ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic