943,703 Members | Top Members by Rank

Ad:
  • JSP Discussion Thread
  • Unsolved
  • Views: 12620
  • JSP RSS
Jul 2nd, 2005
0

Problems with JSTL

Expand Post »
Hi I use the tag library and i have following Problem.

<c : out value="${nickname}"/>

Output of this statement is ${nickname} and not the value of the variable nickname. I have no clue what i m doing wrong. jar's and tld's are in the right directory.

Following is on the top of my jsp.

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

using Tomcat 5.X
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Banshee78 is offline Offline
2 posts
since Jul 2005
Jul 4th, 2005
0

Re: Problems with JSTL

what variable 'nickname' are you trying to output?
JSTL will use any named attribute from the pagecontext, not something you created in a Java block on the JSP (in fact you should avoid those like the plague).
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Jul 4th, 2005
0

Re: Problems with JSTL

yeah that is my problem. You are totaly right. So if i need variables i transfer from my servlet to my JSP <c:out... is not the right way? Should I use <%=.... instead?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Banshee78 is offline Offline
2 posts
since Jul 2005
Jul 8th, 2005
0

Re: Problems with JSTL

When you reference ${nickname} from JSTL, what the JSP is doing is looking in either the request object for a nickname attribute or the session object [i.e., request.getAttribute("nickname")]. So if you want to use ${nickname} from JSTL but set it in your servlet, then do request.setAttribute("nickname", "My Nickname");

If you want to set values in the JSP, then use the <c:set> JSTL tag.

The most important thing about getting JSTL to work, and is documented almost no where, is you have to use a Servlet 2.4 style web.xml instead of a Servlet 2.3 style web.xml.

To do this, make sure the top of your web.xml looks like this:

JSP Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/
  5. ns/j2ee/web-app_2_4.xsd"
  6. version="2.4">
From the sound of things, this might actually be your problem, because if you're using a 2.3 style web.xml, then I don't think it will recognize the EL expressions. ${nickname} is an EL expression.
bpk
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bpk is offline Offline
7 posts
since Jun 2005
Jul 8th, 2005
0

Re: Problems with JSTL

Quote ...
The most important thing about getting JSTL to work, and is documented almost no where, is you have to use a Servlet 2.4 style web.xml instead of a Servlet 2.3 style web.xml.
Wrong, dead wrong.
You need a 2.4 servlet container ONLY to use JSTL 1.1. The questions are clearly related to JSTL 1.0 which is part of the 2.3 spec (though may need separate installation of the JSTL jars depending on appserver in use).
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Jul 8th, 2005
0

Re: Problems with JSTL

This is a Tomcat-specific issue with the Apache JSTL implementation. If you don't use a 2.4 web.xml, the EL expressions don't get evaluated in the JSP.
bpk
Reputation Points: 10
Solved Threads: 0
Newbie Poster
bpk is offline Offline
7 posts
since Jun 2005
Feb 3rd, 2006
0

Re: Problems with JSTL

Many thanks. Nice hint! Before anyone else gets insane one more hint: of course, you have to recompile all jsps to see it work after changing the web.xml.
a
find <docroot> -name "*.jsp" | xargs touch
will do the rest... ;-)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
nylz is offline Offline
1 posts
since Feb 2006
Feb 4th, 2006
0

Re: Problems with JSTL

Quote originally posted by bpk ...
This is a Tomcat-specific issue with the Apache JSTL implementation. If you don't use a 2.4 web.xml, the EL expressions don't get evaluated in the JSP.
Be sure to never tell that to the 30 or so Tomcat instances running with our customers.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JSP Forum Timeline: Passing values to a url and storing in database
Next Thread in JSP Forum Timeline: Array String not working?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC