• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing values to param value dynamically in jsp

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to pass param values dynamically.If i tried to assign a variable to value attribute ,Its saying, must enclose within string. How to assign value dynamically?

My code goes here,


In the place of "12" i want to dynamically pass values.
 
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What did you try, which caused the error?
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried to get the request parameter and pass the value to the applet.

 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Should work, provided EL is on.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Neeba Rebbaca wrote:i tried to get the request parameter and pass the value to the applet.



Not a good idea anyway. Your variable str is not thread safe.
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there any other best practise?
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Neeba Rebbaca wrote:Is there any other best practise?


Without scriptlet you can directly get the reuest params through "${param.nameOfTheParameter}"
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you explain me in detail(because i'm new to J2EE)


do you mean this,

>
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Neeba Rebbaca wrote:can you explain me in detail(because i'm new to J2EE)
do you mean this,
>



"param" is an implicit EL variable (of type Map) which holds request parameter name/value pairs. You can access the parameter value by it's name like above.
 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i tried to get the request parameter and pass the value to the applet.And this is my html,here i want to pass the parameter test's value (2) to the applet







here, the output should display as 2 , but i'm getting only a empty string.where i'm making the mistake.
 
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure whether we can mention any query string in form action, however this should work.

 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Neeba Rebbaca wrote:.. here, the output should display as 2 , but i'm getting only a empty string.where i'm making the mistake.


That's not possible with "form" tag which meant to submit the form data. How ever you can have a "anchor" tag somewhere and that also will work like the "input" tag suggested above.
OR
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Neeba Rebbaca wrote:i tried to get the request parameter and pass the value to the applet.


This will solve your problem
<%=expression %>.These are the expression tags.It is equivalent println statement in java.
 
Swastik Dey
Bartender
Posts: 2270
20
Android Java ME Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Correct, but what you are using is not using expression language which is more recommended these days.
 
Vijitha Kumara
Bartender
Posts: 4116
72
Mac TypeScript Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bhaavyaa K. Kapoor wrote:

Neeba Rebbaca wrote:i tried to get the request parameter and pass the value to the applet.


This will solve your problem
<%=expression %>.These are the expression tags.It is equivalent println statement in java.


Hi Bhaavyaa, Welcome to JavaRanch . These days people never use Java code (scriptlet,scriptlet expressions etc..) in JSPs but JSTL,EL, Standard & Custom actions.
 
Bhaavyaa K. Kapoor
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vijitha Kumara wrote:

Bhaavyaa K. Kapoor wrote:

Neeba Rebbaca wrote:i tried to get the request parameter and pass the value to the applet.


This will solve your problem
<%=expression %>.These are the expression tags.It is equivalent println statement in java.


Hi Bhaavyaa, Welcome to JavaRanch . These days people never use Java code (scriptlet,scriptlet expressions etc..) in JSPs but JSTL,EL, Standard & Custom actions.


Thanks for telling me.I have just started learning jsp and hence i am just a beginner
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic