Struts2:格式错误的OGNL表达

时间:2012-02-28 18:16:02

标签: jquery jsp java-ee struts2 ognl

在我的JSP中,我使用的是名为TagEdit的插件,它必须有一个输入文本字段,其中包含“name ='tag []'”,如下所示:

<s:form theme="simple" action="myActionn" method="post">
    <s:textfield theme="simple" name="tag[]" value="" cssClass="tag"/>
    <sj:submit targets="actionMessageResult"/>
</s:form>

但是当我提交它时,struts2抛出了这个异常:

WARNING: Error setting expression 'tag[]' with value '[Ljava.lang.String;@6c2a78'
ognl.ExpressionSyntaxException: Malformed OGNL expression: tag[] [ognl.ParseException: Encountered " "]" "] "" at line 1, column 5.
Was expecting one of:
    ":" ...
    "not" ...
    "+" ...
    "-" ...
    "~" ...
    "!" ...
    "(" ...
    "true" ...
    "false" ...
    "null" ...
    "#this" ...
    "#root" ...
    "#" ...
    "[" ...
    "{" ...
    "@" ...
    "new" ...
    <IDENT> ...
    <DYNAMIC_SUBSCRIPT> ...
    "\'" ...
    "`" ...
    "\"" ...
    <INT_LITERAL> ...
    <FLT_LITERAL> ...
    ]
    at ognl.Ognl.parseExpression(Ognl.java:112)
    at com.opensymphony.xwork2.ognl.OgnlUtil.compile(OgnlUtil.java:225)
    at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:209)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:173)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:160)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:151)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:292)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:203)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:510)
    at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)
Caused by: ognl.ParseException: Encountered " "]" "] "" at line 1, column 5.
Was expecting one of:
    ":" ...
    "not" ...
    "+" ...
    "-" ...
    "~" ...
    "!" ...
    "(" ...
    "true" ...
    "false" ...
    "null" ...
    "#this" ...
    "#root" ...
    "#" ...
    "[" ...
    "{" ...
    "@" ...
    "new" ...
    <IDENT> ...
    <DYNAMIC_SUBSCRIPT> ...
    "\'" ...
    "`" ...
    "\"" ...
    <INT_LITERAL> ...
    <FLT_LITERAL> ...

    at ognl.OgnlParser.generateParseException(OgnlParser.java:3172)
    at ognl.OgnlParser.jj_consume_token(OgnlParser.java:3051)
    at ognl.OgnlParser.unaryExpression(OgnlParser.java:1236)
    at ognl.OgnlParser.multiplicativeExpression(OgnlParser.java:971)
    at ognl.OgnlParser.additiveExpression(OgnlParser.java:894)
    at ognl.OgnlParser.shiftExpression(OgnlParser.java:750)
    at ognl.OgnlParser.relationalExpression(OgnlParser.java:508)
    at ognl.OgnlParser.equalityExpression(OgnlParser.java:405)
    at ognl.OgnlParser.andExpression(OgnlParser.java:352)
    at ognl.OgnlParser.exclusiveOrExpression(OgnlParser.java:299)
    at ognl.OgnlParser.inclusiveOrExpression(OgnlParser.java:246)
    at ognl.OgnlParser.logicalAndExpression(OgnlParser.java:193)
    at ognl.OgnlParser.logicalOrExpression(OgnlParser.java:140)
    at ognl.OgnlParser.conditionalTestExpression(OgnlParser.java:101)
    at ognl.OgnlParser.assignmentExpression(OgnlParser.java:64)
    at ognl.OgnlParser.expression(OgnlParser.java:23)
    at ognl.OgnlParser.index(OgnlParser.java:2336)
    at ognl.OgnlParser.navigationChain(OgnlParser.java:1331)
    at ognl.OgnlParser.unaryExpression(OgnlParser.java:1196)
    at ognl.OgnlParser.multiplicativeExpression(OgnlParser.java:971)
    at ognl.OgnlParser.additiveExpression(OgnlParser.java:894)
    at ognl.OgnlParser.shiftExpression(OgnlParser.java:750)
    at ognl.OgnlParser.relationalExpression(OgnlParser.java:508)
    at ognl.OgnlParser.equalityExpression(OgnlParser.java:405)
    at ognl.OgnlParser.andExpression(OgnlParser.java:352)
    at ognl.OgnlParser.exclusiveOrExpression(OgnlParser.java:299)
    at ognl.OgnlParser.inclusiveOrExpression(OgnlParser.java:246)
    at ognl.OgnlParser.logicalAndExpression(OgnlParser.java:193)
    at ognl.OgnlParser.logicalOrExpression(OgnlParser.java:140)
    at ognl.OgnlParser.conditionalTestExpression(OgnlParser.java:101)
    at ognl.OgnlParser.assignmentExpression(OgnlParser.java:64)
    at ognl.OgnlParser.expression(OgnlParser.java:23)
    at ognl.OgnlParser.topLevelExpression(OgnlParser.java:15)
    at ognl.Ognl.parseExpression(Ognl.java:110)
    ... 52 more
/-- Encapsulated exception ------------\
ognl.ParseException: Encountered " "]" "] "" at line 1, column 5.
Was expecting one of:
    ":" ...
    "not" ...
    "+" ...
    "-" ...
    "~" ...
    "!" ...
    "(" ...
    "true" ...
    "false" ...
    "null" ...
    "#this" ...
    "#root" ...
    "#" ...
    "[" ...
    "{" ...
    "@" ...
    "new" ...
    <IDENT> ...
    <DYNAMIC_SUBSCRIPT> ...
    "\'" ...
    "`" ...
    "\"" ...
    <INT_LITERAL> ...
    <FLT_LITERAL> ...

    at ognl.OgnlParser.generateParseException(OgnlParser.java:3172)
    at ognl.OgnlParser.jj_consume_token(OgnlParser.java:3051)
    at ognl.OgnlParser.unaryExpression(OgnlParser.java:1236)
    at ognl.OgnlParser.multiplicativeExpression(OgnlParser.java:971)
    at ognl.OgnlParser.additiveExpression(OgnlParser.java:894)
    at ognl.OgnlParser.shiftExpression(OgnlParser.java:750)
    at ognl.OgnlParser.relationalExpression(OgnlParser.java:508)
    at ognl.OgnlParser.equalityExpression(OgnlParser.java:405)
    at ognl.OgnlParser.andExpression(OgnlParser.java:352)
    at ognl.OgnlParser.exclusiveOrExpression(OgnlParser.java:299)
    at ognl.OgnlParser.inclusiveOrExpression(OgnlParser.java:246)
    at ognl.OgnlParser.logicalAndExpression(OgnlParser.java:193)
    at ognl.OgnlParser.logicalOrExpression(OgnlParser.java:140)
    at ognl.OgnlParser.conditionalTestExpression(OgnlParser.java:101)
    at ognl.OgnlParser.assignmentExpression(OgnlParser.java:64)
    at ognl.OgnlParser.expression(OgnlParser.java:23)
    at ognl.OgnlParser.index(OgnlParser.java:2336)
    at ognl.OgnlParser.navigationChain(OgnlParser.java:1331)
    at ognl.OgnlParser.unaryExpression(OgnlParser.java:1196)
    at ognl.OgnlParser.multiplicativeExpression(OgnlParser.java:971)
    at ognl.OgnlParser.additiveExpression(OgnlParser.java:894)
    at ognl.OgnlParser.shiftExpression(OgnlParser.java:750)
    at ognl.OgnlParser.relationalExpression(OgnlParser.java:508)
    at ognl.OgnlParser.equalityExpression(OgnlParser.java:405)
    at ognl.OgnlParser.andExpression(OgnlParser.java:352)
    at ognl.OgnlParser.exclusiveOrExpression(OgnlParser.java:299)
    at ognl.OgnlParser.inclusiveOrExpression(OgnlParser.java:246)
    at ognl.OgnlParser.logicalAndExpression(OgnlParser.java:193)
    at ognl.OgnlParser.logicalOrExpression(OgnlParser.java:140)
    at ognl.OgnlParser.conditionalTestExpression(OgnlParser.java:101)
    at ognl.OgnlParser.assignmentExpression(OgnlParser.java:64)
    at ognl.OgnlParser.expression(OgnlParser.java:23)
    at ognl.OgnlParser.topLevelExpression(OgnlParser.java:15)
    at ognl.Ognl.parseExpression(Ognl.java:110)
    at com.opensymphony.xwork2.ognl.OgnlUtil.compile(OgnlUtil.java:225)
    at com.opensymphony.xwork2.ognl.OgnlUtil.setValue(OgnlUtil.java:209)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.trySetValue(OgnlValueStack.java:173)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:160)
    at com.opensymphony.xwork2.ognl.OgnlValueStack.setValue(OgnlValueStack.java:151)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.setParameters(ParametersInterceptor.java:292)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:203)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:211)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:190)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:90)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:243)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
    at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:192)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
    at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:249)
    at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
    at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:510)
    at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Unknown Source)
\--------------------------------------/

struts.xml:

    <package name="default" extends="struts-default" >
        <interceptors>
            <interceptor-stack name="defaultStack">
                <interceptor-ref name="params">
                    <param name="excludeParams">^tag\..*</param>
                </interceptor-ref>
            </interceptor-stack>
        </interceptors>

        <action name="myActionn" class="com.fap.controller.common.tagAction">
            <result name="success">ajax_result/common/actionMessage/action_message_result_error.jsp</result>
            <result name="error">ajax_result/common/actionMessage/action_message_result_error.jsp</result>
        </action>

    </package>

行动:

public class tagAction extends ActionSupport {

    private static final long serialVersionUID = 1L;

    public String execute() {
        try {
            Map params = (Map) ActionContext.getContext().getParameters();

            String[] entries1 = (String[]) params.get("tag[3-a]");
            String[] entries2 = (String[]) params.get("tag[]");
            for(int i=0;i<entries1.length;i++)
                System.out.println(entries1[i]);
            for(int i=0;i<entries2.length;i++)
                System.out.println(entries2[i]);


        } catch (Exception e) {
            addActionError(e.getMessage());
            e.printStackTrace();
            return "error";
        }
        return "success";
    }
}
我应该怎么做伙计? 谢谢大家

0 个答案:

没有答案