aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes EL won't work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "EL won Watch "EL won New topic
Author

EL won't work

Tiffiny Yang
Ranch Hand

Joined: Mar 29, 2006
Posts: 124
I am learning EL. I can not see the value x using EL

--------------------
<%! int x = 4;%>

<br>
EL expression for x=${x}
----------------------------
I am using apache-tomcat-5.5.17.


Thanks
Anupama Ponnapalli
Ranch Hand

Joined: Jun 12, 2006
Posts: 66
You would have to enable it first

<%@page isELIgnored="false"%>

You would also have to add it to the pageContext as an attribute

pageContext.setAttribute("name", value);
[ March 06, 2007: Message edited by: Anupama Ponnapalli ]
Tiffiny Yang
Ranch Hand

Joined: Mar 29, 2006
Posts: 124
It works!

Thanks Anupama !
Amirr Rafique
Ranch Hand

Joined: Nov 14, 2005
Posts: 324
Can we conclude that for EL to get any variable, it should be some where in pageScope, requestScope etc

Any one please confirm


"Know where to find the solution and how to use it - that's the secret of success."
Anupama Ponnapalli
Ranch Hand

Joined: Jun 12, 2006
Posts: 66
Hi Tiffiny Yang ,

I forgot to mention this: EL is enabled by default. If you are using a servlets 2.4 container like tomcat 5, you do not need to say isELIgnored=false.

Pls check you web.xml to make sure that you are using the right version for you app too. This from one of my apps:

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
...

</web-app>
Anupama Ponnapalli
Ranch Hand

Joined: Jun 12, 2006
Posts: 66
Hi Amir,

yes, the object must be an attribute in one of the 4 scopes. I believe it uses the JspContext findAttribute method internally.

Regards,
Anu
Manju Devarla
Ranch Hand

Joined: Dec 14, 2006
Posts: 85
why is not printing the value of x when we say ${x}

i am using Tomcat 5+..By deafult EL is enabled so what should be done to print this..
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

It will enabled if you actually use the correct version of web.xml.
Please check the following :
http://faq.javaranch.com/view?ElOrJstlNotWorkingAsExpected


[My Blog]
All roads lead to JavaRanch
Manju Devarla
Ranch Hand

Joined: Dec 14, 2006
Posts: 85
my web.xml is correct with
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-app_2.4.xsd"
version="2.4">

but still why the value of x is not getting printed..
Marc Peabody
pie sneak
Sheriff

Joined: Feb 05, 2003
Posts: 4727

Manju, do you have a scoped attribute named x? If you believe that you do, would you minded posting the code to show how you are going about it?


A good workman is known by his tools.
achayya matta
Ranch Hand

Joined: Oct 27, 2005
Posts: 111
Hello manju,
Have you tried the following snippet.
<%pageContext.setAttribute("name", "ashok");%>
my name is ${name}
it works..
Chaminda Amarasinghe
Ranch Hand

Joined: May 17, 2006
Posts: 402
why is not printing the value of x when we say ${x}


because you have not placed "x" in a scope as an attribute.
Manju Devarla
Ranch Hand

Joined: Dec 14, 2006
Posts: 85
<%! int x = 4;%>

<br>

<%pageContext.setAttribute("x", "10");%>

EL expression for x=${x} // prints 10

Now i am able to print value of x as 10..But How do i do it with just
declaration with out setting with pageContext.setAttribute(name,value)

ie The value of x as 4..?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61010
    
  65

You can't. The EL has no access to scripting variables. The whole point of the JSTL and EL is to eliminate the use of scriplets.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EL won't work