aspose file tools*
The moose likes Servlets and the fly likes setting the entered value in a text field to a variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "setting the entered value in a text field to a variable" Watch "setting the entered value in a text field to a variable" New topic
Author

setting the entered value in a text field to a variable

Moieen Khatri
Ranch Hand

Joined: Nov 27, 2007
Posts: 144
Hi,

How can I set the entered the value in a text field below into a String variable?

The code is below



Currently the value from dmmc.cabinet_owner is prepopulated in the text field. I want to modify this prepopulated field and enter some string value.How can I get this user entered value to get stored in a string variable in my servlet so that I can insert it in the db?

Please give some advice on this

Many Thanks!

Shailesh Narkhede
Ranch Hand

Joined: Jul 10, 2008
Posts: 368
After you entered value,
Submit form & action of submit should url of servlet.
In servlets doGet or dopost method just use


Thanks,
Shailesh
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42611
    
  65
Moieen Khatri wrote:out.println("<input type='text' name='owner' value="+dmmc.cabinet_owner+">");

Note that this will fail if the string contains spaces. You need to enclose the value in quotes, like you're doing for the other attributes.


Ping & DNS - my free Android networking tools app
Moieen Khatri
Ranch Hand

Joined: Nov 27, 2007
Posts: 144
Dear Shailesh and Ulf,

Thanks for the replies!




When I check for the value of the entered text field value in the logs using sop statement above I get the null value.Is the value not submitted?Am I making some error for getting the value using req.getParameter?

Thanks

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42611
    
  65
You're missing the quotes I mentioned in my previous post, and you're also missing some spaces between the attributes.
Moieen Khatri
Ranch Hand

Joined: Nov 27, 2007
Posts: 144
Hi Ulf,

I have made changes to the code as described by you:



I still get the null value for req.getParameter("owner"). Is this because its not getting submitted or due to some other issue?

Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42611
    
  65
Oops, I completely missed that: what this code does is create the HTML form - there's no value entered by the user there yet. You'd use the "req.getParameter("owner")" in the servlet that handles the form submission (and which is mapped to "analyzeDocBase"), not in this servlet that merely creates the form.
Moieen Khatri
Ranch Hand

Joined: Nov 27, 2007
Posts: 144

Hi,

Thanks for the reply, I have made changes so that the form is submitted,However I still get a null value for the req.getParameter("owner") variable.Is it because of syntax issues?(quotes and double quotes)Is there a turnaround solution for getting the entered value inside the text field inside my servlet.I have tried several things with the quotes and the double quotes but with no success. The code is posted below:



Please advice as I am stuck with this badly

Thanks!


Harish Ponduri
Greenhorn

Joined: Jun 08, 2009
Posts: 19
Hello Mr. Khatri,

You want the 'owner' value which you have been entering in that servlet and you want to populate in the same servlet is it soo. or in the next servlet as you mentioned 'analyzeDocBase'.

Because you are retrieving by request.getParameter("owner") so you can access in analyzeDocBase servlet because on submit it is going to that given servlet.

One more thing you need to check is<input type="text" name="owner" value='"+omc.ansprech+"' > try with this.
 
 
subject: setting the entered value in a text field to a variable