自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Struts框架SaveNewOrder Action

開發(fā) 后端
這里介紹Struts框架SaveNewOrder Action,這是一個典型的Struts Action;然而,注意這個action的異常配置。

學(xué)習(xí)Struts框架時,經(jīng)常會遇到SaveNewOrder Action問題,這里將介紹SaveNewOrder Action問題的解決方法。

SaveNewOrder Action

示例應(yīng)用的用戶接口層使用Struts框架。這兒我們將討論當(dāng)為一個應(yīng)用分層時和Struts相關(guān)的部分。讓我們從在struts-config.xml文件里檢查一個Action配置開始。

  1. type="com.meagle.action.SaveOrderAction"   
  2. name="OrderForm"   
  3. scope="request"   
  4. validate="true"   
  5. input="/NewOrder.jsp">   
  6. Save New Order   
  7.  
  8. path="/NewOrder.jsp"   
  9. scope="request"   
  10. type="com.meagle.exception.OrderException"/>   
  11.  
  12. path="/NewOrder.jsp"   
  13. scope="request"   
  14. type="com.   
  15. meagle.   
  16. exception.   
  17. OrderMinimumAmountException"/>  

SaveNewOrder Action被用來持久化一個用戶從用戶接口層提交的訂單。這是一個典型的Struts Action;然而,注意這個action的異常配置。這些Exceptions為我們的業(yè)務(wù)服務(wù)對象也在Spring 配置文件(applicationContext-hibernate.xml)中配置了(在transactionAttributes屬性里)。當(dāng)這些異常被從業(yè)務(wù)層擲出我們能在我們的用戶接口里恰當(dāng)?shù)奶幚硭鼈?。第一個異常,OrderException,當(dāng)在持久層里保存訂單對象失敗時將被這個action使用。這將引起事務(wù)回滾和通過業(yè)務(wù)對象傳遞把異常傳回給Struts層。OrderMinimumAmountException,在業(yè)務(wù)對象邏輯里的一個事務(wù)因為提交的訂單達不到最小訂單數(shù)量而失敗也將被處理。然后,事務(wù)將回滾和這個異常能被用戶接口層恰當(dāng)?shù)奶幚怼?/P>

最后一個連接步驟是使我們的表現(xiàn)層和我們的業(yè)務(wù)層交互。這已經(jīng)通過使用前面討論的服務(wù)定位器來完成了。服務(wù)層充當(dāng)一個到我們的業(yè)務(wù)邏輯和持久層的接口。這兒是Struts框架中的SaveNewOrder Action可能怎樣使用一個服務(wù)定位器調(diào)用一個業(yè)務(wù)方法:

  1. public ActionForward execute( ActionMapping mapping, ActionForm form, 
    javax.servlet.http.HttpServletRequest request,
    javax.servlet.http.HttpServletResponse response)   
  2. throws java.lang.Exception {   
  3.  
  4. OrderForm oForm = (OrderForm) form;   
  5.  
  6. // Use the form to build an Order object that   
  7. // can be saved in the persistence layer.   
  8. // See the full source code in the sample app.   
  9.  
  10. // Obtain the wired business service object   
  11. // from the service locator configuration   
  12. // in BaseAction.   
  13. // Delegate the save to the service layer and   
  14. // further upstream to save the Order object.   
  15. getOrderService().saveNewOrder(order);   
  16.  
  17. oForm.setOrder(order);   
  18.  
  19. ActionMessages messages = new ActionMessages();   
  20. messages.add(ActionMessages.GLOBAL_MESSAGE, 
    new ActionMessage("message.order.saved.successfully"));   
  21.  
  22. saveMessages(request, messages);   
  23.  
  24. return mapping.findForward("success");   
  25. }  

【編輯推薦】

  1. 詳細概述Hibernate Struts區(qū)別
  2. Struts 2:一流的AJAX支持
  3. 學(xué)習(xí)比較Struts2和Struts1:Struts2完勝
  4. 如何解決Struts Hibernate的整合問題
  5. 淺析Hibernate Struts分頁
責(zé)任編輯:佚名 來源: IT168
相關(guān)推薦

2009-09-29 11:09:57

服務(wù)定位器Struts Acti

2011-08-11 13:02:43

Struts2Junit

2009-06-04 10:33:10

struts vali框架

2009-06-08 16:45:00

精通StrutsTiles

2009-06-25 15:46:19

HttpServletStruts2教程Action類

2009-02-01 10:05:00

2009-06-23 14:01:27

StrutsTapestryJSF

2009-06-04 07:55:08

Struts框架簡介Struts

2009-06-04 09:11:34

學(xué)習(xí)strutsstruts框架

2009-06-04 11:08:32

struts2 val框架

2015-05-05 11:06:02

JavaJava框架Struts+Hibe

2009-06-18 11:37:24

Struts2中ForJavaScript

2009-06-25 15:37:12

Struts2教程Validation框

2011-03-30 09:03:57

struts2

2009-06-05 09:58:20

struts2驗證用戶注冊

2009-06-19 16:05:39

時間類型Struts

2009-06-03 15:38:37

Struts框架RBAC

2010-01-08 12:03:42

ibmdwREST

2009-02-04 13:13:03

2010-04-20 09:14:33

Struts
點贊
收藏

51CTO技術(shù)棧公眾號