Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setting the entered value in a text field to a variable

 
Moieen Khatri
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After you entered value,
Submit form & action of submit should url of servlet.
In servlets doGet or dopost method just use
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Moieen Khatri
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic