• Post Reply Bookmark Topic Watch Topic
  • New Topic

label value in servlet  RSS feed

 
Singh Anisha
Ranch Hand
Posts: 100
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to fetch label value from jsp page to servlet.

.jsp

in servlet using request.getParameter("hour1");
but its giving null..
How can i achieve this??
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37181
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Labels are just for display. You need an input tag (or other form field tag) in order for a value to get submitted with the form.

For example,
<input id="hour" name="hour2" value="foo" type="hidden" />
 
Singh Anisha
Ranch Hand
Posts: 100
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it mean that we can not fetch value of labels anyhow ??
Or there is some other approach available..
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37181
515
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Singh Anisha wrote:Is it mean that we can not fetch value of labels anyhow ??

You can create a hidden field with the same value.

Let's step back a step though. Your label has a value of "/". Is this really what you are wanting to be submitted? I would think you would want a text field or pull down so users could enter an hour. Either of those would be a form field so you wouldn't be submitting the label.

 
Singh Anisha
Ranch Hand
Posts: 100
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually it is a label which has a timer display through javascript.
and i want to save the time elapse(value on label) in database.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66149
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Labels don't have values and aren't submitted. That's it. No way around it. No work-arounds. End of story.

If you want a value submitted, it'll need to be via an input element or other element that participates in a submission (select, textarea, and so on) as Jeanne has already stated.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66149
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. The label element has no name attribute and it is invalid HTML to give it one.
 
Singh Anisha
Ranch Hand
Posts: 100
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank for all the suggestions and help.
Thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66149
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How I would approach it:

If the content (there is no "value") of the label needs to be submitted, I would do one of:

  • Create an input element of type hidden, and set its value to whatever the label is set to in the script that sets the label's content.
  • or
  • Create an input element of type hidden, and establish a submit handler on the form that copies the label's content to the hidden input as the form is being submitted.

  • Which approach I would choose depends upon considerations that we do not know about your page, but I would likely lean towards the latter as it is more modular.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!