• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using the variables of same JSP page

 
Jibesh Patra
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have got a JSP page .
It has got a textfield.
During run time the textfield is set to some value. I want to know if there is any way of using the value of the textfiled in the same JSP page.

I have tried
String flag=(flag)request.getParameter("nameofthetextfield")

In the action of the form I have put the same jsp page where the textfield resides.

But all the time I get a null value in flag though the textfield displays the changed value.

Any idea how I can extract the value of the textfield
 
Jibesh Patra
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry I have done a typing mistake in the above post please bear with me.

String flag=(flag)request.getParameter("nameofthetextfield")
will be
String flag=(String)request.getParameter("nameofthetextfield")
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can always edit your posts by clicking on the icon.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
getParameter is used for retrieving post parameters or query string parameters from the client.

I'm not completely sure what you mean by "use the value in the same JSP".
Can you explain further?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you cannot. The JSP is executed on the server before the page is sent to the browser where the user can fill in the field.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To clarify a little further: Because all JSP tags operate on the page before it's sent to the browser, you can't access values entered at runtime in JSP code.

However, because JavaScript runs in the browser itself, you can use JavaScript code to access values entered at runtime.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might find this article helpful.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!