my dog learned polymorphism
The moose likes Servlets and the fly likes Can somebody please give any suggestions ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can somebody please give any suggestions ?" Watch "Can somebody please give any suggestions ?" New topic

Can somebody please give any suggestions ?

Mallika Kumar
Ranch Hand

Joined: Feb 15, 2001
Posts: 61
I want to achieve something similar to a transaction in a jsp page. I have to post some parameters to a site, and then update my database accordingly. I'm updating my database only if the post is successful. Here are the scenarios:
1. Post is successful and update is fine on my database.[This is a successful operation.]
2. Post is successful to the site, but update fails for my database. I'm rolling-back the post, ie, I'm sending another post to the site which rolls-back the first post.[This is a failed operation, but the site to which I'm posting, and my database are in sync.]
3. Post is successful, but update fails. While sending the roll-back post, this roll-back post fails. Now, the site and my database are not in sync.[This is a failed operation and a BAD condition if it occurs.]
How can I solve the last occurance ? Is there a way to create transactions in jsps ? Any response will be very helpful.
Thanks in advance.
David Taylor

Joined: Aug 07, 2001
Posts: 1
Sorry, if I'm restating what you stated, but I just wanted to make sure I understand.
Are you needing to respond back to the user that the database update succeeded and if you fail to get a response back to the user, the transaction needs to be rolled back?
If so, you can maintain your database connection between servlet calls ( remember maintaining your jdbc connection with your session, multi-threading, etc.). I'm not sure off the top of my head if you can expect the instance to be the same between calls to a JSP, but this would be better suited to a servlet. The JSP should work if you use a bean to handle the connection, mapping to the session, database update, etc. I'm just not sure with the manner Java Beans are instantiated.
You could just have the jsp reference the servlet with the post, have the servlet begin the transaction ( with a connection to the database that is maintained outside of the service/dopost method and tied to this user's session ). Then, if the user responds with a confirmation, or you complete your display of the page within the servlet, confirm your transaction, else rollback if you timeout or the user is not displayed a confirmation.
Let me know if I'm in the ball park, else, sorry for being useless. I'm studying for a certification tonight, but tomorrow pm I could continue this.
Good luck
David Taylor

David Taylor<BR>Diversified Development, Inc.<BR><BR>mailto://<BR>mailto:// - Alpha Pager<BR>Client/Server and Internet Specialists<BR>
I agree. Here's the link:
subject: Can somebody please give any suggestions ?
jQuery in Action, 3rd edition