Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet doubts

 
Ashok Pradhan
Ranch Hand
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my App there is an html file with two textfield(num1,num2)and two button named add and substract.



after entering two numbers in the textfield and clicking any button of the two button then the app should display the desired result (num1+num2) or (num1-num2) for that I have created a servlet(first time I have created the app with only one button (add)then it works fine).

But my problem is how the servlet know which button is clicked

my previous servlet code is:-


What are the changes need in the App to work ,Please clarify my doubt...
[ November 11, 2008: Message edited by: Ashok Pradhan ]
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13077
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that the INPUT tag can take a NAME attribute. With that NAME you can get the VALUE associated with that input button.


Bill
 
Ashok Pradhan
Ranch Hand
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my App I have made these changes:

in html:


AND
in Servlet



but till now I cannot get why I am getting

str=null;
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the browser does not send anything for a button that is not clicked.

If you have two buttons, add and subtract, and the user clicks on the add button, its name and value will be sent to the server in the post string.
Nothing will be sent up for the subtract button so request.getParameter("subtract") will return null.
[ November 11, 2008: Message edited by: Ben Souther ]
 
Ashok Pradhan
Ranch Hand
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben,But surprisingly the add button also return null.
 
Ashok Pradhan
Ranch Hand
Posts: 180
Eclipse IDE Firefox Browser Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ben,Now I go it :-

I have made these changes:
String str = request.getParameter("add");
tehn it returns add

thanks ,now you have cleared my confusion.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic