如何在struts2中从验证中排除操作方法

如何在struts2中从验证中排除操作方法,struts2,Struts2,我的动作课有以下几种方法 1.add 2.edit 3.loadEdit 4.remove 5.list 6.execute 在这里,我需要对添加和编辑应用验证..如何在struts.xml中进行配置 <action name="editComment" method="edit" class="com.mmm.ehspreg2.web.action.product.CommentAction"> <result name="success">/

我的动作课有以下几种方法

1.add
2.edit
3.loadEdit
4.remove
5.list
6.execute
在这里,我需要对添加和编辑应用验证..如何在struts.xml中进行配置

<action name="editComment" method="edit"
        class="com.mmm.ehspreg2.web.action.product.CommentAction">
    <result name="success">/jsp/propertyManager/loadList.jsp</result>
</action>
<action name="removeComment" method="remove"
        class="com.mmm.ehspreg2.web.action.product.CommentAction">
    <interceptor-ref name="validation">
        <param name="excludeMethods">remove</param>
    </interceptor-ref>
    <result type="tiles">listComment</result>
    <result type="tiles" name="input">listComment</result>
</action>

/jsp/propertyManager/loadList.jsp
去除
列表注释
列表注释

当我这样配置它时,不会调用remove action方法。我不明白这个问题。请协助。

只需在excludeMethods参数中列出您不希望通过验证框架运行的所有方法。由于您只需要验证
添加
编辑
,请按如下所示列出其他4项:

<interceptor-ref name="validation">
    <param name="excludeMethods">loadEdit,remove,list,execute</param>
</interceptor-ref>

加载编辑、删除、列出、执行

您可以在中了解更多信息。

您也可以在action类中的方法初始化之前使用@SkipValidation

e、 g

@SkipValidation
公共字符串保存(){
字符串结果=super.save();
如果(结果等于(保存)){
setMessage1(getText(“save.successful”);
}否则{
setMessage1(getText(“save.unsuccessful”);
}
jsonResponse=newhashtable();
放置(字段为jsonResponse状态,
密钥(JSONRESPONSE(应答)消息(成功);
put(字段为jsonResponse消息,
键(JSONRESPONSE(空字符串);
put(字段_jsonResponse_值,domainModel.getId());
//System.out.println(“domainModel>>>>>”+domainModel.getId());
返回结果;
}

它不工作。我对每个方法都有不同的操作。我是否需要在所有操作中指定此excludethods配置?不,您可以在struts.xml的顶部定义自己的defaultStack。如果您在此页面上查找“defaultStack”,您将看到当前正在运行的内容。将其复制到您自己的配置中,并更改所需内容:
@SkipValidation
public String save() {
    String result = super.save();
    if (result.equals(SAVE)) {
        setMessage1(getText("save.successful"));
    } else {
        setMessage1(getText("save.unsuccessful"));
    }
    jsonResponse = new Hashtable<String, Object>();
    jsonResponse.put(FIELD_JSONRESPONSE_STATUS,
            KEY_JSONRESPONSE_MESSAGE_SUCCESS);
    jsonResponse.put(FIELD_JSONRESPONSE_MESSAGE,
            KEY_JSONRESPONSE_EMPTY_STRING);
    jsonResponse.put(FIELD_JSONRESPONSE_VALUE, domainModel.getId());
    // System.out.println("domainModel>>>>>>" + domainModel.getId());
    return result;
}