Reputation: 29
I have a JSP with several text fields. User must fill the desired field and submit his choice with "Submit" button. For example, if he want to change his e-mail or phone number he insert new value to text field and press "Submit". I send action to "myServlet" and here I have a problem... How can I determine from which field value was sending?
Upvotes: 0
Views: 172
Reputation: 2633
As raddykrish said all of your fields get submitted to your servlet.
Suppose email and phnum are your text fields , you can read them by
request.getparameter('email');
request.getparameter('phnum');
you can check which one was null and determine which field was submitted
String email=null;
String phnum=null;
if(request.getparameter('email')!=null){
email=request.getparameter('email');
}
else{
phnum=request.getparameter('phnum');
}
Upvotes: 1
Reputation: 1866
Basically in a submit action all the elements under the form will be submitted to the servlet. Suppose there are ten text fields under the form tag all the 10 fields will be submitted to the servlet. You can use tools like HttpFox to see the post parameters. The parameters goes as key value pairs. The key will be the name of the element and value will be the actual value entered by the user.
for example if you have an input field by name phone number
If the user enters as 345 678 9878 then in the post request the value will go to the servlet as phonenumber=345 678 9878. Like this all form values will be sent back to the servlet.
Upvotes: 1
Reputation: 1108852
Compare the initial value with the new value.
if (!oldValue.equals(newValue)) {
// Value has changed.
}
Upvotes: 0