How to assign the value in a text field to a variable in jsp using Java

Reply

Join Date: Dec 2007
Posts: 65
Reputation: CodeBoy101 is an unknown quantity at this point 
Solved Threads: 0
CodeBoy101's Avatar
CodeBoy101 CodeBoy101 is offline Offline
Junior Poster in Training

How to assign the value in a text field to a variable in jsp using Java

 
0
  #1
Jun 21st, 2009
Hi all. I was wondering if there's a way to assign the value in a text field to a variable in jsp using Java (not Javascript). Normally in Javascript you might do something like: document.formName.fieldName.value to access the value. How can this be achieved using Java?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,701
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 228
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: How to assign the value in a text field to a variable in jsp using Java

 
0
  #2
Jun 21st, 2009
If you want to use java it must be done at the server. Meaning before you render the page.
For example.
Put a value at the request request.setAttribute("key","The Value") Then submit, redirect or whatever and at jsp, get it and put it at the field:
  1. String something = (String)request.getAttribute("key");
  2. ...
  3.  
  4. <input type="text" name="someName" value="<%= something %>" />
Last edited by javaAddict; Jun 21st, 2009 at 12:25 pm.
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 65
Reputation: CodeBoy101 is an unknown quantity at this point 
Solved Threads: 0
CodeBoy101's Avatar
CodeBoy101 CodeBoy101 is offline Offline
Junior Poster in Training

Re: How to assign the value in a text field to a variable in jsp using Java

 
0
  #3
Jun 21st, 2009
Cool, so what about if it's from form to form on the same page?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 65
Reputation: CodeBoy101 is an unknown quantity at this point 
Solved Threads: 0
CodeBoy101's Avatar
CodeBoy101 CodeBoy101 is offline Offline
Junior Poster in Training

Re: How to assign the value in a text field to a variable in jsp using Java

 
0
  #4
Jun 21st, 2009
By that I mean going from textfield --> variable --> textfield all on the same page.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,701
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 228
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: How to assign the value in a text field to a variable in jsp using Java

 
0
  #5
Jun 22nd, 2009
If you have a value in a textfield and want to put it in a java variable, you need to submit the form (or pass it as parameter at a hyperlink)

If you want to put a java variable to a textfield, when you go to the page you need to take it from the request and put it to the field when the page renders.

Remember first the code executes at the server and then the page is loaded. So you take the value from the request and then the field with the value will be displayed:
  1. String something = (String)request.getAttribute("key");
  2. ...
  3. <input type="text" name="someName" value="<%= something %>" />
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 65
Reputation: CodeBoy101 is an unknown quantity at this point 
Solved Threads: 0
CodeBoy101's Avatar
CodeBoy101 CodeBoy101 is offline Offline
Junior Poster in Training

Re: How to assign the value in a text field to a variable in jsp using Java

 
0
  #6
Jun 22nd, 2009
At the server huh, so what should I do if I wanted that process to take place in after the page loaded?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,701
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 228
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: How to assign the value in a text field to a variable in jsp using Java

 
0
  #7
Jun 22nd, 2009
Meaning put some value to a field and then push something so that this value would be put to a java variable?

Yes, submit the page.

When you see the JSP page, java code has already been executed. If you want to execute some more you need to go to the server by submitting.
If you have java code in a jsp page, that code is first executed at the server and then page is displayed.
So when you submit, the code that gets executed (getting values from the request) is at the server. When this is done, you see the page
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for JSP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC