jpetstore的一段代码,请高手解释一下什么意思啊

04-12-08 luowei
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);

}

}

banq
2004-12-11 11:20
根据request中不同的方法名进行转发控制。

猜你喜欢