• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

c:out problem

 
Edward Kenworthy
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simplifying, my problem is that whilst:
<cut value="date"/> works (printing out the literal text 'date'
What I actually want is to print out the value of the date (date is declared like this:
<jsp:useBean id="date" class="java.util.Date" />

However when I try:
<cut value="${date}"/>
Tomcat 5 throws this exception:

org.apache.jasper.JasperException: /FirstJSP.jsp(11,0) According to TLD or attribute directive in tag file, attribute value does not accept any expressions
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:83)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:404)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:183)
org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:979)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:734)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1444
<snipped>

Any ideas?
[ May 29, 2004: Message edited by: Edward Kenworthy ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which JSP version, JSTL version and JSTL tld are you using?
 
Edward Kenworthy
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Bear Bibeault:
Which JSP version, JSTL version and JSTL tld are you using?


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

So 1.0- everything else is as comes with Tomcat 5.0
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With Tomcat 5 (JSP 2.0) you should be using JSTL 1.1 and make sure that your web.xml declares your app as a Servlet 2.4 app (uses the 2.4 xml schema versus the 2.3 DTD).
 
Edward Kenworthy
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's exactly what was required, I changed <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> to <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> and it works.

Thankyou.
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use <c:set var="date" value="<%= new java.util.Date() %>"/> instead of the useBean tag.

That (or something very similar) should work

[edited to fix notation]
[ June 01, 2004: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While the <c:set notation can be used when creating a new bean, be aware that it is not a general replacement for <jsp:useBean, which still has a role (albeit, a diminished one) in the JSP 2.0/JSTL world.
[ June 01, 2004: Message edited by: Bear Bibeault ]
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sure, but AFAIK jsp:useBean can't put a bean in a place where c ut can find it?
Or maybe specific mention of the bean scope in the jsp:useBean and c ut is required if you do use jsp:useBean.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65342
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure it does. The behaviour of useBean is to find and, if you use the class attribute, create if not found, a bean of the specified class in the specified scope.

These scopes are the same as that searched by the JSTL.

Take for example:



this ends up as (using Tomcat 5):



The behavior is to create a scripting variable (which I never use since I no longer use Java scripting on pages in JSP 2.0 unless I absolutely have to) as well as to conditionally create the bean in request scope.

The JSTL doesn't care how the bean got there, it searches the scopes for variables which is just picks up by name. So whether xyz was placed on the request by a JSTL tag, jsp:useBean, or (as is very common in my code) a servlet controller, the JSTL tags will "see" it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic