JiveJdon Community Forums
在线165人 Home | 论坛 | 培训咨询 | 精华 | 查搜 | 注册 | 登陆 |
首页 » 论坛 » 设计模式、框架和架构
???en_US.forumThreadPrev.name??? 上一主题
Go back to the topic listing   返回主题列表
???en_US.forumThreadNext.name??? 下一主题
这个主题共有 1 回复 / 1 页 [ ]  发表新帖子  回复该主题贴
luowei

发表文章: 118
注册时间: 2004年07月01日 15:23
给他发消息
jpetstore的一段代码,请高手解释一下什么意思啊 发表: 2004年12月08日 21:16 回复
jpetstore的一段代码,请高手解释一下什么意思啊
public class BeanAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {

String forward = "success";

try {

ActionContext.initialize(request, response);

if (form != null) {

// Explicit Method Mapping
Method method = null;
String methodName = mapping.getParameter();
if (methodName != null && !"*".equals(methodName)) {
try {
method = form.getClass().getMethod(methodName, null);
forward = (String) method.invoke(form, null);
} catch (Exception e) {
throw new BeanActionException("Error dispatching bean action via method parameter ('" + methodName + "'). Cause: " + e, e);
}
}

// Path Based Method Mapping
if (method == null && !"*".equals(methodName)) {
methodName = mapping.getPath();
if (methodName.length() > 1) {
int slash = methodName.lastIndexOf("/") + 1;
methodName = methodName.substring(slash);
if (methodName.length() > 0) {
try {
method = form.getClass().getMethod(methodName, null);
forward = (String) method.invoke(form, null);
} catch (Exception e) {
throw new BeanActionException("Error dispatching bean action via URL pattern ('" + methodName + "'). Cause: " + e, e);
}
}
}
}
}

} catch (Exception e) {
request.setAttribute("BeanActionException", e);
throw e;
}

return mapping.findForward(forward);
}
ljshan

发表文章: 15
注册时间: 2004年11月29日 14:18
给他发消息
Re: jpetstore的一段代码,请高手解释一下什么意思啊 发表: 2004年12月09日 13:02 回复
没有什么复杂的呀,就是简化了对Struts的依赖,用户只要直接写formbean就可以了。这种formbean要么不写(form == null),要么直接将操作方法写进来,然后返回forward名称。具体被调用的方法通过什么方式指明有两种方式:1)action的名字2)通过actionmapping中的parameter指定。这样做的好处是可以将操作与属性统一到一起,更加符合POJO的思想。
这个主题有 1 回复 / 1 页 [ ]
???en_US.forumThreadPrev.name??? 上一主题
Go back to the topic listing   返回主题列表    返回页首  返回页首
???en_US.forumThreadNext.name??? 下一主题
热点TAG: AOP cache DDD EJB 集群 设计模式 Hibernate IOC JiveJdon OO RBAC Spring Struts
查询本论坛内 回复超过的热门帖子
快速发表回复
标题
 
粗体 斜体 下划线 插入图片 插入代码 插入url链接 插入附件
内容
 

解惑之道在J道 ,打造中国最具影响力的的企业软件社区
OpenSource JIVEJDON v3.0 Powered by JdonFramework Code © 2002-08 jdon.com

anti spam