• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Can somebody please give any suggestions ?

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic