Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing values to param value dynamically in jsp

 
Neeba Rebbaca
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • 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.
 
Vijitha Kumara
Bartender
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
i tried to get the request parameter and pass the value to the applet.

 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Should work, provided EL is on.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Is there any other best practise?
 
Vijitha Kumara
Bartender
Posts: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • 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
  • 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: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Swastik Dey
Rancher
Posts: 1609
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • 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: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • 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
 
Bhaavyaa K. Kapoor
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 1609
5
Android Java Java ME
  • Mark post as helpful
  • send pies
  • 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: 3914
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic