aspose file tools*
The moose likes JSP and the fly likes EL Execution Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "EL Execution Problem" Watch "EL Execution Problem" New topic
Author

EL Execution Problem

Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
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 ?


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Daniel Rhoades
Ranch Hand

Joined: Jun 30, 2004
Posts: 186
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


Drinking more tea is the key...
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
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.

ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

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

Joined: Nov 15, 2004
Posts: 1026
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

Joined: Jan 24, 2005
Posts: 489



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

Joined: Nov 15, 2004
Posts: 1026
The Dog class has a public String getName() method.
Daniel Rhoades
Ranch Hand

Joined: Jun 30, 2004
Posts: 186
Could you post your dog and person class
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61661
    
  67



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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61661
    
  67

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

Joined: Nov 15, 2004
Posts: 1026
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: EL Execution Problem