IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope:Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  Web development | Java technology | Open source  >

Ruby on Rails 和 J2EE:两者能否共存?

两个 Web 应用程序框架的比较

developerWorks

返回文章


清单 1. DeleteOrderAction.java
				// Package and Import statements omitted
01 public class DeleteOrderAction extends Action {
02
03   public ActionForward execute(ActionMapping mapping, ActionForm form,
04            HttpServletRequest req, HttpServletResponse res) throws Exception {
05        
06     String value = req.getParameter("id");     // Get the order id from the request
07     Long id = new Long(value);
08
09     deleteOrder(id);
10
11     return mapping.findForward("success");  // Forward to ListOrdersAction
12   }
13
14   private void deleteOrder(Long id) {
15     Session session = HibernateUtil.currentSession();  // Get a session object
16     Transaction tx = null;
17  
18     try {
19       tx = session.beginTransaction();               // Begin the transaction
20       session.delete(new Order(id));                 // Delete the Order object
21       tx.commit();                                   // Commit the transaction
22     } finally {
23       HibernateUtil.closeSession();                  // Close the session
24     }
25   }
26 }

返回文章

    关于 IBM 隐私条约 联系 IBM 使用条款