fresher

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", "UPDATET" & "DELETE" respectively on

a HTML page and 3 TextFields to accept values. The problem is to

accept values from the user and depending on the button clicked

any of the three operations are carried out.if i click ADD button a row is to be added to the db ,if i click UPDATE button a row is to be modified to the db,if i click DELETE button a row is to be deleted to the db

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.

[816 byte] By [ybkrishnavenia] at [2007-11-27 6:45:35]
# 1
Assign the buttons a name and find out using HttpServletRequest#getParameter() which button was clicked (when the value is not null).
BalusCa at 2007-7-12 18:17:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

hi,

write the html code like this.

<form action="/cri/test" method="POST">

<input type="submit" name="btn" value="Add"/>

<input type="submit" name="btn" value="Update"/>

<input type="submit" name="btn" value="Delete"/>

</form>

action = /cri/test --> iT's u'r servlet name

Your servlet will look like this,

String s = request.getParameter("btn");

if(s.equals("Add")) {

// insert Code

}

else if(s.equals("Update")) {

// update code

}

else {

// delete code

}

i think this code snippet will help u to complete your application.

Bala

art84a at 2007-7-12 18:17:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...