Chapter 8. Accessing Beans From a Servlet
8.3. Initiating a Transaction From a Servlet
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 ;
}
...
37
Need help?
Do you have a question about the APPLICATION SERVER - JONAS and is the answer not in the manual?
Questions and answers