This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Pie
Posts: 1793
20
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 171
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
J. Kevin Robbins
Bartender
Pie
Posts: 1793
20
Chrome Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay...thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
shihab shahriar,
Your post was moved to a new topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic