Can 3 buttons on a HTML Page , be handled by servlets

Hello Everyone. I am a beginner at J2EE so this question might be silly for you but please be kind and help me out. Here is the problem:

There are 3 buttons "ADD", "SUBTRACT" & "MULTIPLY" respectively on a HTML page and 2 TextFields to accept 2 values. The problem is to accept 2 values from the user and depending on the button clicked any of the three operations are carried out.

I want to use a servlet to do this. In Core Java we have ActionListener to listen for events and then depending on the ActionEvent object's 'trapped' event the suitable processing is done.

But how to implement this in HTML and Servlet?

Can anybody give me the sample code for both HTML and Servlet?

[719 byte] By [arijit_dattaa] at [2007-10-3 1:20:41]
# 1

In Java/JSP you don't have events like in Swing.

All you have is an HTTPRequest with some parameters sent along.

You can call request.getParameter() to retrieve those values and then manipulate them around.

In this case I would name the fields "field1" and "field2"

I would give all the buttons the same name (eg "op", and values "add", "subtract" and "multiply"

You can then call request.getParameter("op") to find out which of the three buttons the user pressed, and can take the operation.

Good luck,

evnafets

evnafetsa at 2007-7-14 18:17:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Hey THANKSSSSSSSSSS SOOOOOOOOOO MUCH!! It worked wonderfully!! Thanks once again!
arijit_dattaa at 2007-7-14 18:17:52 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...