jpetstore的一段程式碼,請高手解釋一下什麼意思啊

luowei發表於2004-12-08
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);
}

}

相關文章