Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can somebody please give any suggestions ?

 
Mallika Kumar
Ranch Hand
Posts: 61
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic