这两天看JPetStore(ibatis和struts),我原想把struts标签都改成el和jstl(需要加standard和jstl jar文件)。结果把html 改的过程出了很多问题,html:text /areatext /radio/checkbox/ select/ option必须包含在html:form中,它们的property要对应form 的action对应的bean,select/ option比较麻烦。所以总结出来,改造过程可以分两步走:1 html:from部分不变,其中还涉及验证,2bean和logic可以改为el和jstl,不过改了之后竟然识别不出来。。郁闷,只好先暂停。。
在程序中文件的后缀名改为shtml,每一个页面都经过servlet。
下面是beanaction的内容:
private static final String NO_METHOD_CALL = "*";
private static final String SUCCESS_FORWARD = "success";
public final ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
String forward = SUCCESS_FORWARD;
try {
if (!(form instanceof BaseBean)) {
if (form != null) { ........... } else { .............. }
}
BaseBean bean = (BaseBean) form;
ActionContext.initCurrentContext(request, response);
if (bean != null) {
// Explicit Method Mapping
Method method = null;
String methodName = mapping.getParameter();
if ( methodName != null && !NO_METHOD_CALL.equals(methodName)) {
try {
method = bean.getClass().getMethod(methodName, null);
synchronized (bean) {
forward = bean.getInterceptor().intercept(new ActionInvoker(bean, method));
}
} catch (Exception e) {
..........
}
}
// Path Based Method Mapping
if ( method == null && !NO_METHOD_CALL.equals(methodName)) {
methodName = mapping.getPath();
if (methodName.length() > 1) {
int slash = methodName.lastIndexOf("/") + 1;
methodName = methodName.substring(slash);
if (methodName.length() > 0) {
try {
method = bean.getClass().getMethod(methodName, null);
synchronized (bean) {
forward = bean.getInterceptor().intercept(new ActionInvoker(bean, method));
}
} catch (Exception e) {
.......
}
}
}
}
}
} catch (Exception e) {
forward = "error";
request.setAttribute("BeanActionException", e);
}
return mapping.findForward(forward);
}
BeanActionException(RuntimeException) 很值得学习4个构造函数 super()/super(string)/super(throwable)/super(string,throwable)
ActionContext (cookieMap parameterMap requestMap sessionMap applicationMap/request/response)
abstract class BaseHttpMap拥有四个抽象的方法getNames() /getValue()/putValue()/removeValue())
abstract class BaseHttpMap implements Map 要实现map的一些方法。
throw new UnsupportedOperationException("Cannot put value to ParameterMap.");
在程序中文件的后缀名改为shtml,每一个页面都经过servlet。
下面是beanaction的内容:
private static final String NO_METHOD_CALL = "*";
private static final String SUCCESS_FORWARD = "success";
public final ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
String forward = SUCCESS_FORWARD;
try {
if (!(form instanceof BaseBean)) {
if (form != null) { ........... } else { .............. }
}
BaseBean bean = (BaseBean) form;
ActionContext.initCurrentContext(request, response);
if (bean != null) {
// Explicit Method Mapping
Method method = null;
String methodName = mapping.getParameter();
if ( methodName != null && !NO_METHOD_CALL.equals(methodName)) {
try {
method = bean.getClass().getMethod(methodName, null);
synchronized (bean) {
forward = bean.getInterceptor().intercept(new ActionInvoker(bean, method));
}
} catch (Exception e) {
..........
}
}
// Path Based Method Mapping
if ( method == null && !NO_METHOD_CALL.equals(methodName)) {
methodName = mapping.getPath();
if (methodName.length() > 1) {
int slash = methodName.lastIndexOf("/") + 1;
methodName = methodName.substring(slash);
if (methodName.length() > 0) {
try {
method = bean.getClass().getMethod(methodName, null);
synchronized (bean) {
forward = bean.getInterceptor().intercept(new ActionInvoker(bean, method));
}
} catch (Exception e) {
.......
}
}
}
}
}
} catch (Exception e) {
forward = "error";
request.setAttribute("BeanActionException", e);
}
return mapping.findForward(forward);
}
BeanActionException(RuntimeException) 很值得学习4个构造函数 super()/super(string)/super(throwable)/super(string,throwable)
ActionContext (cookieMap parameterMap requestMap sessionMap applicationMap/request/response)
abstract class BaseHttpMap拥有四个抽象的方法getNames() /getValue()/putValue()/removeValue())
abstract class BaseHttpMap implements Map 要实现map的一些方法。
throw new UnsupportedOperationException("Cannot put value to ParameterMap.");