| Author |
Simple EL code is not working
|
Sangeetha Raja
Greenhorn
Joined: Dec 18, 2008
Posts: 28
|
|
Hi All
I am trying to write EL program. Could any of you please help me to get the output? I am expecting the value zero to be displayed. Do I need to import any jars?
<html>
<body>
Integer Testing
<%! int a = 0; %>
Value of a: ${a}
</body>
</html>
Result
Integer Testing
Value of a:
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56229
|
|
The EL knows nothing of scripting variables. The EL works with scoped variables.
This is not surprising as the JSTL and EL is mean to supplant the use of scripting in JSPs. not to work with it.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Sangeetha Raja
Greenhorn
Joined: Dec 18, 2008
Posts: 28
|
|
|
ok. Thank you.
|
 |
Sangeetha Raja
Greenhorn
Joined: Dec 18, 2008
Posts: 28
|
|
Hi all
Again one more question/doubt.
I am trying to write a EL program wiht arithmetic expression.
<HTML>
<HEAD>
<TITLE>EL Testing</TITLE>
</HEAD>
<BODY>
<H3>Fill-out-form</H3>
<FORM action="ELSample.jsp" method="GET">
<input type="text" name="A">
<input type="text" name="B">
<input type="submit" value="Submit Name">
</FORM>
The A is: ${param.A}
The B is: ${param.B}
Integer Testing
The Sum is: ${param.B} + ${param.A}
</BODY>
</HTML>
Result:
The A is: 2
The B is: 3
Integer Testing
The Sum is: 3 + 2
After updating the integers in the text boxes once i click submit button, i am getting the above result.
I understand that A & B are string variables , getting concatenated. How to do summation with EL. Can any one of you help me on this?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56229
|
|
The Sum is: ${param.B} + ${param.A}
How could it possibly know that these are suppoed to be related? They are two entirely separate expressions, each to be evaluated separately.
Think for a moment -- how could you tell the JSP translator that this is intended to be a single expression?
|
 |
Sangeetha Raja
Greenhorn
Joined: Dec 18, 2008
Posts: 28
|
|
hey.. i got
The Sum is: ${param.B + param.A}
Thank you...
Can you please provide me some link where i can find EL related materials and JSTL.. i have some but not that much informative....
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Sangeetha Raja wrote:Can you please provide me some link
www.google.com
|
 |
Sangeetha Raja
Greenhorn
Joined: Dec 18, 2008
Posts: 28
|
|
Thanks
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56229
|
|
|
Links to the specs can be found in the FAQ.
|
 |
Sangeetha Raja
Greenhorn
Joined: Dec 18, 2008
Posts: 28
|
|
Thank you!!!
I am trying to access java bean from Jsp with EL.
In ELTest1.html; I am getting 2 values
I have Person.java with 2 attributes String name; private Dog dName; (along with getter, setter) Also Dog.java with attribute String dogName; (along with getter, setter)
Person.java
In Servlet, ELTest1Servlet I am assigning the values to bean and forwarding to JSP;
In Jsp, ELTest.jsp: I am trying to display the bean values...
I am getting the error,
[2/5/09 22:50:29:920 EST] 00000028 ServletWrappe E SRVE0068E: Could not invoke the service() method on servlet /ELTest.jsp. Exception thrown : javax.servlet.ServletException: Unable to find a value for "dName" in object of class "foo.Person" using operator "."[/b][/b]
Anything wrong in my code? Pleae anyone of you help me to fix this.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56229
|
|
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.
You can go back and change your post to add code tags by clicking the button on your post.
|
 |
Sangeetha Raja
Greenhorn
Joined: Dec 18, 2008
Posts: 28
|
|
|
Thank you. I updated.
|
 |
Vikas Kapoor
Ranch Hand
Joined: Aug 16, 2007
Posts: 1374
|
|
Hello Sangeetha,
Can you please show us your complete servlet? and both java bean classes?
|
 |
Vikas Kapoor
Ranch Hand
Joined: Aug 16, 2007
Posts: 1374
|
|
Duplication of above post.
Please delete this. Shouldn't we have control over our post atleast?
|
 |
Sangeetha Raja
Greenhorn
Joined: Dec 18, 2008
Posts: 28
|
|
|
i updated the java and servlet classes
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
You should avoid property names which have a capital letter as the second character. I ran into the same problem when I tried to use "eMailAddress" as a property name. Something about the way the JavaBean rules change that into a method name (which I forget the exact problem now).
|
 |
Vikas Kapoor
Ranch Hand
Joined: Aug 16, 2007
Posts: 1374
|
|
Not sure but, try putting nullary(no arg) constructor in both beans.This is one of few JavaBean conventions
I guess you use HFSJ. you can also cross check with the code they have provided.
|
 |
Sangeetha Raja
Greenhorn
Joined: Dec 18, 2008
Posts: 28
|
|
its working if change the Caps to small..
I not yet tried with const....
Thanks a lot..
|
 |
Sangeetha Raja
Greenhorn
Joined: Dec 18, 2008
Posts: 28
|
|
The no arg constructor is not fixing the issue.
Thanks
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56229
|
|
Did you change the property names to be more appropriate?
Even without the JavaBean standards, why would you use a name like getDName() instead of getDogName()? There is no need to "freeze dry" names like this. It's needless obfuscation.
|
 |
 |
|
|
subject: Simple EL code is not working
|
|
|