• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

EL Execution Problem

 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I executed a web application by setting request attribute and forwarding the request from servlet to jsp. I used EL expression in Jsp to get the value of the attribute set in Servlet. But there is no output in the page. When I use jsp:usebean and jsp:getProperty I am getting the desired results. I am using tomcat 5.0.28. Is it a problem with tomcat ?
 
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most likely a scoping issue, try ${requestScope.my_attribute_name} if that doesn't work, can you post the line in your servlet that sets the attribute and the EL expression that you are using
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to print the nested properties. Properties of Properties explained in page:366. ${person.name} is working fine and printing the expected result. But ${person.dog.name} is not printing any value. I did the same thats explained the book.

 
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Things to check out for.

1. Are you using servlet 2.4 spec (you can make it out from your dtd/schema reference in your web.xml). For servlet 2.3, EL is ignored by default.
Quick fix- add <%@page isELIgnored = "false"%> in your jsp. Better option is to upgrade your app to 2.4

Change your web.xml to refer to the 2.4 schema



2. Are you using the right jars for JSTL 1.1 (Jakarta Standard Taglibs 1.1.2) ?

3. Are you referring to the jstl 1.1 tld in your jsps. The jar files have the 1.0 and the 1.1 tlds and class files. You should have this in your jsps.


cheers,
ram.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using servlet 2.4 and jsp 2.0. Jsp is working fine for ${person.name}
Only If I try to print nested properties I am getting no output. ${person.dog.name}

I couldn't understand 2 and 3. Should I import any jar file into my project. I included the code given by you in 3. But the jsp is showing error as File Not Found.
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


in which case, the only thing to look out for is does the Dog class have a public getName() method ?

Regarding 2 & 3, you need that only if you are using jstl tags (which you arent obviously and which I missed in my previous post) - so you neednt have any jars or taglib attributes in your jsp - sorry for those red-herrings.

cheers,
ram.
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Dog class has a public String getName() method.
 
Daniel Rhoades
Ranch Hand
Posts: 186
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you post your dog and person class
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Sheriff
Posts: 67590
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


Your Dog accessor creates a new instance of Dog every time it is accessed, ensuring that it is never possible for the Dog's name to be anything other than null.
[ October 03, 2005: Message edited by: Bear Bibeault ]
 
ramprasad madathil
Ranch Hand
Posts: 489
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also the property names doesnt match with the get/set methods. In the person class, the Dog variable is 'd', whereas the methods are getDog() and setDog(). Same in the Dog class too with the 'dogname' property.

I guess you can get away with it in EL, since it just looks up the method name. Thus as long as you use person.dog, the getDog() method would be called. But your code wouldnt be terribly readable if you carry on in such fasion.

cheers,
ram.
 
Bear Bibeault
Sheriff
Posts: 67590
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 Dog variable is 'd', whereas the methods are getDog() and setDog()



That is completely moot. What the internal variable is named makes no difference whatsoever. For readability purposes, it should make sense, but it can be whatever the author chooses it to be.

That said, d is indeed a horrible choice for a variable name.
[ October 03, 2005: Message edited by: Bear Bibeault ]
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the answer as well understood the mistake. Modified the code as



Wrong Code:



This code returns a new Dog instance when ever its been called from the JSP instead of returning the Dog instance set from servlet code.

Thanks Bear Bibeault, ramprasad madathil, Daniel Rhoades.
 
reply
    Bookmark Topic Watch Topic
  • New Topic