老妖的博客
          現實的中沒有幾個人能夠真為對方去死,甚至山盟海誓很快就會在金錢面前變的微不足道,這才是生活。沒有永遠的愛,除了你的父母對你,當然也就沒有永遠的恨,更沒有永遠的痛,時間是最好的治療大師,它會很快撫平你心靈上累累的傷痕。很多年以后你想起來時,那些在你生命中洶涌來往的人群至多是個模糊的影子或者毫無意義的名字
          posts - 105,  comments - 171,  trackbacks - 0

          service層編寫商業邏輯總會有很多的返回信息,那么如何合理的和struts/webwork結合起來呢,我參考了spring論壇上的一個做法如下:

           1/** 
           2 * 
           3 */
           
           4package it.linksystem.csai.web.util; 
           5
           6import java.util.Iterator; 
           7
           8import it.linksystem.csai.client.delegate.UserBusinessDelegate; 
           9import it.linksystem.csai.common.Error; 
          10import it.linksystem.csai.common.Warning; 
          11import it.linksystem.csai.common.dto.UserDTO; 
          12
          13import javax.servlet.http.HttpServletRequest; 
          14
          15import org.apache.struts.action.ActionMessage; 
          16import org.apache.struts.action.ActionMessages; 
          17
          18import net.sf.acegisecurity.Authentication; 
          19import net.sf.acegisecurity.AuthenticationException; 
          20import net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken; 
          21import net.sf.acegisecurity.ui.AbstractProcessingFilter; 
          22
          23/** 
          24 * @author Srepfler Srgjan 
          25 * 
          26 */
           
          27public class LoginProcessingFilter extends AbstractProcessingFilter 
          28
          29   /* (non-Javadoc) 
          30    * @see net.sf.acegisecurity.ui.AbstractProcessingFilter#getDefaultFilterProcessesUrl() 
          31    */
           
          32   public String getDefaultFilterProcessesUrl() 
          33      return "/LoginSubmit.do"
          34   }
           
          35
          36   /* (non-Javadoc) 
          37    * @see net.sf.acegisecurity.ui.AbstractProcessingFilter#attemptAuthentication(javax.servlet.http.HttpServletRequest) 
          38    */
           
          39   public Authentication attemptAuthentication(HttpServletRequest request) 
          40         throws AuthenticationException 
          41      ActionMessages errors = new ActionMessages(); 
          42      ActionMessages warnings = new ActionMessages(); 
          43       
          44      UserBusinessDelegate ubd = new UserBusinessDelegate(); 
          45      String username = request.getParameter("j_username"); 
          46      String password = request.getParameter("j_password"); 
          47      if(username == null)
          48         username =""
          49      }
           
          50      if(password == null)
          51         password=""
          52      }
           
          53      UserDTO userDTO = new UserDTO(); 
          54      userDTO.setUsername(username); 
          55      userDTO.setPassword(password); 
          56      UserDTO resultDTO = ubd.login(userDTO.getUsername(),userDTO.getPassword()); 
          57       
          58      if(resultDTO.isError())
          59         for (Iterator theiterator = resultDTO.errorsIterator(); theiterator.hasNext();) 
          60            Error theerror = (Error) theiterator.next(); 
          61            errors.add(theerror.getCode(),new ActionMessage(theerror.getCode())); 
          62         }
           
          63      }
           else 
          64         if(resultDTO.isWarning())
          65            for (Iterator theiterator = resultDTO.warningsIterator(); theiterator.hasNext();) 
          66               Warning thewarning = (Warning) theiterator.next(); 
          67               warnings.add(thewarning.getCode(),new ActionMessage(thewarning.getCode())); 
          68            }
           
          69         }
           
          70         request.getSession().setAttribute(Constants.USER_KEY,resultDTO); 
          71         logger.info("Login dell utente: "+resultDTO.getUsername()); 
          72      }
           
          73       
          74      UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(username,password); 
          75      authRequest.setDetails(request.getRemoteAddr()); 
          76      return this.getAuthenticationManager().authenticate(authRequest); 
          77   }
           
          78
          79}
           
          80
          DTO撤掉,然后并到service層的BaseService中,做個接口用來記錄error message,然后Baseservice的實現中提供Errors message add和Iterator,以及iserror,iswarning,然后其他service調用其方法,至于view層調用則跟上述類似。
          posted on 2005-09-28 22:30 老妖 閱讀(829) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          <2005年9月>
          28293031123
          45678910
          11121314151617
          18192021222324
          2526272829301
          2345678

          常用鏈接

          隨筆分類(48)

          隨筆檔案(104)

          好友鏈接

          我的豆瓣

          積分與排名

          • 積分 - 221812
          • 排名 - 257

          最新評論

          閱讀排行榜

          主站蜘蛛池模板: 文成县| 九寨沟县| 开原市| 重庆市| 台江县| 绥江县| 台中县| 莱芜市| 茶陵县| 三江| 长春市| 沙坪坝区| 富宁县| 尼玛县| 泊头市| 娱乐| 玉树县| 荥经县| 苍梧县| 莱芜市| 崇礼县| 阿克苏市| 那曲县| 太和县| 白城市| 宝鸡市| 汝阳县| 沿河| 万山特区| 东平县| 江油市| 正宁县| 丽水市| 孟津县| 会理县| 若尔盖县| 南宫市| 朝阳市| 石台县| 桐乡市| 牡丹江市|