File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Displaying Buttons on same JSP page after submition of data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Displaying Buttons on same JSP page after submition of data" Watch "Displaying Buttons on same JSP page after submition of data" New topic
Author

Displaying Buttons on same JSP page after submition of data

Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Hi All
I'm not sure whether this topic should be posted here or in JSP forum but feel this is the right place.

I have a set of JSP pages which take user input and update in the database through servlets. After the user inserts the data successfully, he should be given an option whether he would like to insert another record to the same table. How can I do this in the same JSP page(remember that the data is populated through servlets)? Suppose the data is inserted successfully, I should be able to display a message that data is inserted successfully on the same JSP page and then it should also contain 2 options(probably 2 buttons), "Yes" -if he wishes to insert another record to the same table and "No" -if he is done with record insertion and redirect him to another page.

How can I insert buttons in servlet program since these buttons should be displayed only after successful record insertions. Is there any way out for this?
[ January 02, 2009: Message edited by: Bear Bibeault ]

Thanks & Regards
Swapna Gouri
I "try", I "catch" and "finally" WIN !!!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Upon success, set a scoped variable that indicates this in the request, and forward to the JSP page where you can make decisions based upon the setting (or absence) of this variable.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Hi Bear
This is what I have done, but this is not what I want.
There are 10 JSP pages from which user can enter data into 10 tables of the database. Once the data is submitted he is directed to a HTML page where he has 2 options along with the note that data is submitted successfully. 1)YES-if he wishes to enter data into the same table through page(same) which he entered previously.2) NO-if he is done with entering data into the database.

Now my problem is if he clicks on YES I should be able to direct him back to the same page. Since I have around 10 different pages, how can I get back to the same page? I mean, is there any way to dynamically get back to the same page from which he entered the data previously? Another option could be without redirecting to a HTML page but displaying the message on the same JSP page and giving him an option of selecting YES or NO. How can I do this?
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Swapna Gouri Kalanidhi:
I mean, is there any way to dynamically get back to the same page from which he entered the data previously? Another option could be without redirecting to a HTML page but displaying the message on the same JSP page and giving him an option of selecting YES or NO. How can I do this?


Bear already mentioned in his post . there are two things help you

1.RequestDispatcher 2.sendRedirect (Thik about this )
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
You can store the page's URL in an appropriately scoped variable, and then redirect/forward to the stored page if the user chooses to enter more data.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Swapna Gouri Kalanidhi
Ranch Hand

Joined: Mar 14, 2008
Posts: 107
Hi All
I have used RequestDispatcher and now my program is working as expected.

Thanks a lot for helping me !!!
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by Swapna Gouri Kalanidhi:
Thanks a lot for helping me !!!


you are welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Displaying Buttons on same JSP page after submition of data