struts2 2.3版本 action不能提交?参数的原因是源码中截取了?后的
FormTag--》Form(evaluateClientSideJsEnablement)--》ServletUrlRenderer(renderFormUrl)
从继承树看出form继承closingbean,closingbean继承uibean(CTRL+单击)
从继承树看出form继承closingbean,closingbean继承uibean
fromtag 调用form构造函数
Form extends ClosingUIBean
ClosingUIBean extends UIBean
ClosingUIBean中:
public boolean start(Writer writer) {
boolean result = super.start(writer);
try {
evaluateParams();
mergeTemplate(writer, buildTemplateName(openTemplate, getDefaultOpenTemplate()));
} catch (Exception e) {
LOG.error("Could not open template", e);
}
return result;
}
调用uibean中:
evaluateParams{
populateComponentHtmlId
}
uiBean:
populateComponentHtmlId(form);
Form:
@Override
protected void populateComponentHtmlId(Form form) {
if (id != null) {
addParameter("id", escape(id));
}
// if no id given, it will be tried to generate it from the action attribute
// by the urlRenderer implementation
urlRenderer.renderFormUrl(this);
}
ServletUrlRenderer:
public void renderFormUrl(Form formComponent) {
String namespace = formComponent.determineNamespace(formComponent.namespace, formComponent.getStack(), formComponent.request);
String action;
if(formComponent.action != null) {
action = formComponent.findString(formComponent.action);
} else {
// no action supplied? ok, then default to the current request
// (action or general URL)
ActionInvocation ai = (ActionInvocation) formComponent.getStack().getContext().get(
ActionContext.ACTION_INVOCATION);
if (ai != null) {
action = ai.getProxy().getActionName();
namespace = ai.getProxy().getNamespace();
} else {
// hmm, ok, we need to just assume the current URL cut down
String uri = formComponent.request.getRequestURI();
action = uri.substring(uri.lastIndexOf('/'));
}
}
Map actionParams = null;
if (action != null && action.indexOf("?") > 0) {
String queryString = action.substring(action.indexOf("?") + 1);
actionParams = urlHelper.parseQueryString(queryString, false);
action = action.substring(0, action.indexOf("?"));
}
ActionMapping nameMapping = actionMapper.getMappingFromActionName(action);
String actionName = nameMapping.getName();
String actionMethod = nameMapping.getMethod();
final ActionConfig actionConfig = formComponent.configuration.getRuntimeConfiguration().getActionConfig(
namespace, actionName);
if (actionConfig != null) {
ActionMapping mapping = new ActionMapping(actionName, namespace, actionMethod, formComponent.parameters);
String result = urlHelper.buildUrl(formComponent.actionMapper.getUriFromActionMapping(mapping),
formComponent.request, formComponent.response, actionParams, null, formComponent.includeContext, true);
formComponent.addParameter("action", result);
// let's try to get the actual action class and name
// this can be used for getting the list of validators
formComponent.addParameter("actionName", actionName);
try {
Class clazz = formComponent.objectFactory.getClassInstance(actionConfig.getClassName());
formComponent.addParameter("actionClass", clazz);
} catch (ClassNotFoundException e) {
// this is OK, we'll just move on
}
formComponent.addParameter("namespace", namespace);
// if the name isn't specified, use the action name
if (formComponent.name == null) {
formComponent.addParameter("name", actionName);
}
// if the id isn't specified, use the action name
if (formComponent.getId() == null && actionName!=null ) {
formComponent.addParameter("id", formComponent.escape(actionName));
}
} else if (action != null) {
// Since we can't find an action alias in the configuration, we just
// assume the action attribute supplied is the path to be used as
// the URI this form is submitting to.
// Warn user that the specified namespace/action combo
// was not found in the configuration.
if (namespace != null && LOG.isWarnEnabled()) {
LOG.warn("No configuration found for the specified action: '" + actionName + "' in namespace: '" + namespace + "'. Form action defaulting to 'action' attribute's literal value.");
}
String result = urlHelper.buildUrl(action, formComponent.request, formComponent.response, null, null, formComponent.includeContext, true);
formComponent.addParameter("action", result);
// namespace: cut out anything between the start and the last /
int slash = result.lastIndexOf('/');
if (slash != -1) {
formComponent.addParameter("namespace", result.substring(0, slash));
} else {
formComponent.addParameter("namespace", "");
}
// name/id: cut out anything between / and . should be the id and
// name
String id = formComponent.getId();
if (id == null) {
slash = result.lastIndexOf('/');
int dot = result.indexOf('.', slash);
if (dot != -1) {
id = result.substring(slash + 1, dot);
} else {
id = result.substring(slash + 1);
}
formComponent.addParameter("id", formComponent.escape(id));
}
}
// WW-1284
// evaluate if client-side js is to be enabled. (if validation
// interceptor does allow validation eg. method is not filtered out)
formComponent.evaluateClientSideJsEnablement(actionName, namespace, actionMethod);
}
相关推荐
在Struts2 Action中,接收这些参数,应用到原图并保存裁剪后的版本。 **源码分析**: 查看提供的博文链接(可能已失效,这里假设其包含具体示例代码),你可以深入理解Struts2中的文件上传和下载实现细节。源码通常...
Struts原理、开发及项目实施 Holen 2002-9-12 <br/>1、 摘要 2、 关键词 3、 Framework 4、 Struts的起源 5、 Struts工作原理 6、 Struts安装 7、 一个实例 8、 Struts优缺点...
Struts1之url截取 先我们来对ActionServlet深层次进行分析。我们用断点的调试的方式来看底层源码。因为这个实例是post方式提交,所以将断点设置到doPost方法上。 我们debug运行程序,进入doPost里面的方法:...
84.9. 题目1:用1、2、2、3、4、5这六个数字,用java写一个main函数,打印出所有不同的排列,如:512234、412345等,要求:"4"不能在第三位,"3"与"5"不能相连. 117 84.10. 写一个方法,实现字符串的反转,如:输入...
Struts2,Spring,Hibernate JSP Javascript,jQuery,AJAX 某些工具类及组件如(FileUtil,POI,DateUtils) JS组件:日期组件、富文本编辑器、Fusionchart(图表组件) 抽取Action、Service、Dao,全局异常处理 权限控制...