dcsimg

Can my JSP pages be "transctive" and initiate a transaction or is this possible only with EJBs?

Bozidar Dangubic

A Jsp compiles into a servlet. According to the specification, a servlet can start and commit/rollback its own transactions. So, you can obtain a user transaction from JNDI via java:comp/env/UserTransaction from within your scriptlet code and fire away!

Content ic = new InitialContext();
UserTransaction ut = (UserTransaction) ic.lookup("java.comp/UserTransaction");
ut.begin();
try {
   //transactional stuff
   ut.commit(); 
} catch (Exception e) {
   ut.rollback();
}