aspose file tools*
The moose likes Servlets and the fly likes how to create insert, update, delete buttons on the same page? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to create insert, update, delete buttons on the same page?" Watch "how to create insert, update, delete buttons on the same page?" New topic
Author

how to create insert, update, delete buttons on the same page?

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 931
i created a program which has three classes, my program is inserting, updating, deleting, fetching records from database, and my code is working perfectly for me, but i created this for console:

Here is my three classes:
EmpDbComponent.java



Employee.java


Test.java


now what i want is i create a from in html, for these employee records and i have three buttons on the same page (ie. Insert, Update, Delete) how do i call functions of my EmpDbComponent class on each button click..?? all three buttons are on the same form..
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1106

Have you ever written a jsp page before?

if you have made many jsps before what exact problem are you having? if not can I recommend the head first servlets and jsp book, it is a modern classic.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 931
i am using servlet here, and the problem is i don't know how to i pass one function of one servlet as a of one button click,
for a single button i just create a from and on the action i pass that servlet. but for multiple buttons how do i do this, although i have same form on my page...
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 931
my question is simply how can i add multiple buttons (ie.add/update/delete) in my form, in which i can use functions of EmpDbComponent on each button call
Test.java is i use for console, but now i m using servlet
here is my servlet i am using for these operations



and this servlet i am calling on a form submit, and i want to perform more operations on the same form, not only displaying how can i do this??
J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 632
    
    7

If I'm understanding your question correctly, one possibility is to assign names to your buttons. Upon form submit, the name of the button will be passed as one of the form parameters and you can use that in the servlet to determine which button was clicked.

Myself, I would use JavaScript to catch the click events and use AJAX to perform the CRUD operations.


"There is no reason for any individual to have a computer in his home" ~ Ken Olson, Co-founder of DEC, 1977
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 931
well i don't know how to do this with ajax and javascript...
and okay, i assign names to my three buttons, how my servlet will know which button is pressed and which function needs to invoke..??
what i need to do for this??
Kumaravadivel Subramani
Ranch Hand

Joined: Jul 05, 2008
Posts: 166

Any request which hits servlet, will be processed by get() or post() which is depends on your form submit method. You have to set a html element to indicate which element has been clicked(this is very basis idea to use)so that it would send to servlet as a parameter. Based on the flag you can process call your method.


No pain, No gain.
OCJP 1.6
J. Kevin Robbins
Ranch Hand

Joined: Dec 16, 2010
Posts: 632
    
    7

The name and value of the button that is clicked will be passed as a request parameter. Look at the docs for request.getParameterNames(). Loop through that enumeration checking for your button names and branch accordingly.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60049
    
  65

The button mane will be part of the request parameters.

Wendy is correct. You need to go back and do some reading. This sort of thing is a very basic concept in JSP and servlets and will be covered in any good book on the subject.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 931
okay...thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60049
    
  65

shihab shahriar,
Your post was moved to a new topic.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to create insert, update, delete buttons on the same page?
 
Similar Threads
writing and reading simple data in XML
persistence.xml file for MS SQL Server 2000
help solving dynamic method invocation exception.
Hashtable