老妖的博客
现实的中没有几个人能够真为对方去死,甚至山盟海誓很快就会在金钱面前变的微不足道,这才是生活。没有永远的爱,除了你的父母对你,当然也就没有永远的恨,更没有永远的痛,时间是最好的治疗大师,它会很快抚平你心灵上累累的伤痕。很多年以后你想起来时,那些在你生命中汹涌来往的人群至多是个模糊的影子或者毫无意义的名字
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 老妖 阅读(809) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 

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

常用链接

随笔分类(48)

随笔档案(104)

好友链接

我的豆瓣

积分与排名

  • 积分 - 218793
  • 排名 - 256

最新评论

阅读排行榜