Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Store value from parameter in a variable using EL  RSS feed

 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am using, Tomcat 5.5 and servlet 2.4
I have a doubt with regards to using request parameters using EL. The Situation is as follows: -
1) From one jsp to another i pass two form parameters "num1" and "num2"
2) In the receiving jsp, i want to access them using EL ...i.e., param expression.
3) I am able to access, but i want to store the two values in two variables.

How do i store values after retrieving from the param expression ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by omkar patkar:
1) From one jsp to another i pass two form parameters "num1" and "num2"
I assume by "pass' that you mean via a form submission?

2) In the receiving jsp, i want to access them using EL ...i.e., param expression.
Shouldn't be a problem. Is it?

3) I am able to access, but i want to store the two values in two variables.
What kind of variables? If you mean scoped variables, then <c:set> will do that -- though I'd ask why. Since the data is available via the param builtin variable, why bother to copy it? ("For readability and clarity" is usually a good reason).

If you're talking about scripting variables, the answer is: don't.
[ July 06, 2008: Message edited by: Bear Bibeault ]
 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, from the first jsp page i pass these two parameters (... as form submission...) along with one more parameter, which will dictate the kind of arithmetic operation to be done, i.e., whether Addtion, Subtraction, Division or Multiplication needs to be done with the two parameters.

So, i was thinking JUST FOR ONCE i will get the values from the "param" expression into two variables (...i was thinking of scripting variables). and then based upon the operation to be performed, like Addition, Subtraction etc., i will reuse the two variables and perform the operation.

if i perform the arithmetic operation using param expression, then for different operation selected every time, the param expression will be evaluated ! i hope i am right ?

So, is there any way by which i can achieve this ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, are you talking about with JSTL and EL, or scriptlets?

If the former, <c:set> will work nicely.
 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ammmm..... i don't know how to put this ....but something like this :-

<%

int i = ${param["num1"]};
int j = ${param["num2"]};

Storing their values
%>

${i + j}
${i * j}
${i / j}
${i - j}

something like this....i mean mixing expresion language and scriptlets ?
is it possible ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by omkar patkar:
something like this....i mean mixing expresion language and scriptlets ?
is it possible ?
While it is possible (with more code than you have there) it's definitely a very very very very very and did I mention, very, bad idea.

Either use modern JSTL and EL, or use scriptlets. Mixing them just makes a big mess.
 
omkar patkar
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
k .... so i need to set the two values from the param expression in c:set and use them to perform operation ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, it depends upon what type of operations you want to perform. If using the EL, then, for readability you can use <c:set>. For example, let's say you had a request param named fred that you wanted to assign to barney for readability in later operations:

You can reference barney in later EL expressions and it will have the same value as the fred parameter.

If you will be using scriptlets, just dispense with the JSTL and EL and use Java statements:

[ July 07, 2008: Message edited by: Bear Bibeault ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!