JOnAS v2.4 Tutorial | ||
---|---|---|
<<< Previous | Accessing beans from a Servlet | Next >>> |
It is better to initiate the transactions from the beans, however in some cases you want the transaction to be initiated from the servlet. In this case, proceed as follows:
... try { Context initialContext = new InitialContext(); UserTransaction utx = (javax.transaction.UserTransaction) initialContext.lookup("java:comp/UserTransaction"); utx.begin(); ... do some interesting work here ... if (success) utx.commit(); else utx.rollback(); } catch (Exception ignore) { return ; } ... |
<<< Previous | Home | Next >>> |
Retrieving a home interface and creating a bean | Up | Accessing beans from a JSP |