1

当我在 Struts 2 中提交表单时,ERRORdevMode设置为true. 虽然这不会影响我的功能,但不确定为什么会发生这种情况。

//错误信息

14:34:54,748 ERROR [com.opensymphony.xwork2.interceptor.ParametersInterceptor] (http-localhost/127.0.0.1:8080-1) ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'x' on 'class com.abc.LoginAction: Error setting expression 'x' with value '[Ljava.lang.String;@154cfc5'
14:34:54,749 ERROR [com.opensymphony.xwork2.interceptor.ParametersInterceptor] (http-localhost/127.0.0.1:8080-1) ParametersInterceptor - [setParameters]: Unexpected Exception caught setting 'y' on 'class com.abc.LoginAction: Error setting expression 'y' with value '[Ljava.lang.String;@114b526'

下面是代码片段

// Login JSP
<s:form action="login">
<table>
    <tr><td>UserName : </td><td><s:textfield name="userid"/></td>
    <tr><td>Password : </td><td><s:password name="password"/></td>
    <tr><td></td><td><s:submit value="Submit" /></td>
</table>
</s:form>

Action处理表单提交的类

public class LoginAction implements ModelDriven<LoginForm> {
    private LoginForm theForm = new LoginForm();
    public LoginForm getModel() {
        return theForm;
    }
    public String execute() throws Exception {
        -----
        -----
    }
}

// POJO used for data binding.
public class LoginForm {
    private String userid;
    private String password;
    // Setters and Getters
    
}
4

1 回答 1

1

您在请求中有额外的参数,因为您在操作类中没有公共访问器。但是,如果您不需要 Struts 拦截器处理多余的参数,那么您可以配置此拦截器以排除这些参数。

在示例Struts 2 ModelDriven Action 如何排除某些属性被更新时,您可以找到使用 xml 配置执行此操作的代码。其他示例可能会使用我的答案中提供的注释配置。

这些额外的参数来自哪里很难说,可能你有一些类型的输入字段image

于 2016-06-15T13:58:10.837 回答