我正在尝试将项目从 struts 2.2.3 升级到 struts 2.3.15.1。在升级版本后,应用程序正在运行,但每次我提交一个页面时,它都会在日志中抛出一个非常长的警告。似乎 ParametersInterceptor 试图在我的类中设置一个名为“action:PersonalInfo_next”的属性,它是提交按钮表单元素的名称。这个名称是由 struts 创建的,但是当表单返回时,它会将其视为标准表单字段并尝试为我保存它。
我尝试将 action:.* 添加到 struts.xml 中的 excludeParams 选项,但似乎没有效果:
<interceptor-ref name="params">
<param name="excludeParams">dojo\..*,action:.*</param>
</interceptor-ref>
警告如下:
10/09/13 15:16:18,939 DEBUG [ com.opensymphony.xwork2.interceptor.ParametersInterceptor ]: Parameter [action:PersonalInfo_next] didn't match acceptedPattern pattern!
10/09/13 15:16:18,939 WARN [ com.opensymphony.xwork2.ognl.OgnlValueStack ]: Error setting expression 'action:PersonalInfo_next' with value '[Ljava.lang.String;@47773'
ognl.ExpressionSyntaxException: Malformed OGNL expression: action:PersonalInfo_next [ognl.ParseException: Encountered " ":" ": "" at line 1, column 7.
Was expecting one of:
<EOF>
"," ...
"=" ...
"?" ...
"||" ...
"or" ...
"&&" ...
"and" ...
[snip]
at ognl.Ognl.parseExpression(Ognl.java:112)
at com.opensymphony.xwork2.ognl.OgnlUtil.compile(OgnlUtil.java:268)
at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:230)
at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:183)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:170)
at com.opensymphony.xwork2.ognl.OgnlValueStack.setParameter(OgnlValueStack.java:148)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:318)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:231)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
[snip]
Caused by: ognl.ParseException: Encountered " ":" ": "" at line 1, column 7.
Was expecting one of:
<EOF>
"," ...
"=" ...
"?" ...
[...]
每次提交都会有超过 300 行这样的内容。
乍一看,我认为这可能与这个问题有关,但是当 devMode 被明确禁用时会发生这种情况。由于它是一个警告并且应用程序正在运行,我还玩弄了通过 log4j 配置忽略它的想法,但看起来大部分都直接打印到 stdout 或 stderr 所以这也不是一个选项。
作为参考,这里是我的 struts.xml 中的相关操作元素:
<action name="PersonalInfo_*" class="project.web.actions.EditPersonalInfo" method="{1}">
<interceptor-ref name="defaultStack">
<param name="store.operationMode">AUTOMATIC</param>
</interceptor-ref>
<result name="input">/jsp/personalInfo.jsp</result>
<result name="next" type="redirectAction">
<param name="parse">true</param>
<param name="actionName">Address_open</param>
<param name="namespace">/</param>
<param name="id">${id}</param>
</result>
</action>
还有来自 JSP 的表单和提交元素:(JSP 相当大)
<s:form action="PersonalInfo_personalInfo" namespace="/" id="appForm" cssClass="form personal_info" autocomplete="off">
[lots of fields]
<s:submit value="Next" cssClass="ksu-button" action="PersonalInfo_next"/>