Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/344.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当Struts2中的结果类型为redirect action时,prepare()方法被调用两次_Java_Configuration_Struts2_Interceptor_Prepare - Fatal编程技术网

Java 当Struts2中的结果类型为redirect action时,prepare()方法被调用两次

Java 当Struts2中的结果类型为redirect action时,prepare()方法被调用两次,java,configuration,struts2,interceptor,prepare,Java,Configuration,Struts2,Interceptor,Prepare,我有以下动作类: @Namespace("/admin_side") @ResultPath("/WEB-INF/content") @ParentPackage(value="struts-default") public final class FabricAction extends ActionSupport implements Serializable, ValidationAware, Preparable, ModelDriven<Fabric> { @Aut

我有以下动作类:

@Namespace("/admin_side")
@ResultPath("/WEB-INF/content")
@ParentPackage(value="struts-default")
public final class FabricAction extends ActionSupport implements Serializable, ValidationAware, Preparable, ModelDriven<Fabric>
{
    @Autowired
    private final transient FabricService fabricService=null;
    private static final long serialVersionUID = 1L;

    private int pageSize=5;
    private Long id;
    private Boolean deleteOneRow;
    private Boolean deleteMultipleRows;
    private String message;
    private List<Long>chk;
    private Long deleteId;

    private Long begin;
    private Long end;
    private Long currentPage=1L;
    private Long rowCount;
    private Long totalPages;
    private Integer status;

    private Fabric entity=new Fabric();
    private List<Fabric>fabrics=new ArrayList<Fabric>();

    //Getters & Setters.

    @Action(value = "Fabric",
            results = {
                @Result(name=ActionSupport.SUCCESS, location="Fabric.jsp"),
                @Result(name = ActionSupport.INPUT, location = "Fabric.jsp")},
            interceptorRefs={
                @InterceptorRef(value="paramsPrepareParamsStack", params={"params.acceptParamNames", "id, currentPage, rowCount, totalPages, message, status", "validation.validateAnnotatedMethodOnly", "true", "validation.excludeMethods", "load"})})
    public String load() throws Exception
    {
        //Invokes, when the page is loaded.
        return ActionSupport.SUCCESS;
    }

    @Action(value = "FabricPage",
        results = {@Result(name=ActionSupport.SUCCESS, location="Fabric.jsp", params={"namespace", "/admin_side", "actionName", "Fabric", "currentPage", "${currentPage}"}),
        @Result(name = ActionSupport.INPUT, location = "Fabric.jsp")},
        interceptorRefs={
            @InterceptorRef(value="conversionError"),
            @InterceptorRef(value="paramsPrepareParamsStack", params={"params.acceptParamNames", "currentPage", "validation.validateAnnotatedMethodOnly", "true"})})
    public String page()
    {
        //Invokes, when a page link is clicked.
        return ActionSupport.SUCCESS;
    }

    @Validations(
            requiredStrings={
                @RequiredStringValidator(fieldName="fabricName", type= ValidatorType.FIELD, key = "fabric.name.required")},
            stringLengthFields={
                @StringLengthFieldValidator(fieldName="fabricName", type= ValidatorType.FIELD, minLength="2", maxLength="45", key="fabric.name.length", messageParams={"2", "45"})})
    @Action(value = "AddFabric",
        results = {
            @Result(name=ActionSupport.SUCCESS, type="redirectAction", location="Fabric.jsp", params={"namespace", "/admin_side", "actionName", "Fabric", "currentPage", "${currentPage}", "message", "${message}", "id", "${id}", "status", "${status}"}),
            @Result(name = ActionSupport.INPUT, location = "Fabric.jsp")},
        interceptorRefs={
            @InterceptorRef(value="conversionError"),
            @InterceptorRef(value="paramsPrepareParamsStack", params={"params.acceptParamNames", "id, fabricId, fabricName, currentPage, rowCount, totalPages, status", "validation.validateAnnotatedMethodOnly", "true"})
        })
    public String insert()
    {
        //Handles insert and update operations.
        return ActionSupport.SUCCESS;
    }

    @Action(value = "EditFabric",
            results = {
                @Result(name=ActionSupport.SUCCESS, location="Fabric.jsp"),
                @Result(name = ActionSupport.INPUT, location = "Fabric.jsp")},
            interceptorRefs={
                @InterceptorRef(value="paramsPrepareParamsStack", params={"params.acceptParamNames", "id, fabricId, fabricName, currentPage", "validation.validateAnnotatedMethodOnly", "true"}),
                @InterceptorRef(value="conversionError")})
    public String edit()
    {
        //Invokes, when an edit link is clicked.
        return ActionSupport.SUCCESS;
    }

    @Validations(
            fieldExpressions={@FieldExpressionValidator(fieldName="deleteOneRow", expression="deleteOneRow==true", shortCircuit=true, key="delete.row.reject")})
    @Action(value = "DeleteFabric",
            results = {
                @Result(name=ActionSupport.SUCCESS, type="redirectAction", location="Fabric.action", params={"currentPage", "${currentPage}", "message", "${message}", "status", "${status}"}),
                @Result(name = ActionSupport.INPUT, location = "Fabric.jsp")},
            interceptorRefs={
                @InterceptorRef(value="paramsPrepareParamsStack", params={"params.acceptParamNames", "deleteId, deleteOneRow, currentPage, status", "validation.validateAnnotatedMethodOnly", "true"}),
                @InterceptorRef(value="conversionError")})
    public String deleteSingleRow()
    {
        //Handles deletion of a single row.
        return ActionSupport.SUCCESS;
    }

    @Validations(
            requiredFields={
                @RequiredFieldValidator(type= ValidatorType.FIELD, fieldName="chk", key="delete.multiple.alert"),
                @RequiredFieldValidator(type= ValidatorType.FIELD, fieldName="deleteMultipleRows", key="delete.multiple.confirm")})
    @Action(value = "DeleteFabrics",
            results = {
                @Result(name=ActionSupport.SUCCESS, type="redirectAction", location="Fabric.jsp", params={"namespace", "/admin_side", "actionName", "Fabric", "currentPage", "${currentPage}", "message", "${message}", "status", "${status}"}),
                @Result(name = ActionSupport.INPUT, location = "Fabric.jsp")},
            interceptorRefs={
                @InterceptorRef(value="paramsPrepareParamsStack", params={"params.acceptParamNames", "deleteMultipleRows, chk, currentPage, rowCount, totalPages", "validation.validateAnnotatedMethodOnly", "true"}),
                @InterceptorRef(value="conversionError")})
    public String deleteMultipleRows()
    {
        //Handles deletion of multiple rows.
        return ActionSupport.SUCCESS;
    }

    public Fabric getEntity() {
        return entity;
    }

    public void setEntity(Fabric entity) {
        this.entity = entity;
    }

    public List<Fabric> getFabrics()
    {
        return fabrics;
    }

    @Override
    public Fabric getModel()
    {
        return entity;
    }

    @Override
    public void prepare() throws Exception
    {
        fabrics= fabricService.getList((int)(currentPage-1)*pageSize, pageSize);
    }
}
@名称空间(“/admin\u-side”)
@结果路径(“/WEB-INF/content”)
@ParentPackage(value=“struts default”)
公共最终类FabriAction扩展ActionSupport实现可序列化、ValidationAware、可准备、模型驱动
{
@自动连线
私有最终瞬态FabricService FabricService=null;
私有静态最终长serialVersionUID=1L;
私有int pageSize=5;
私人长id;
私有布尔deleteOneRow;
私有布尔删除多线程;
私有字符串消息;
私人上市公司;
私有长deleteId;
私人长跑;
私人长尾;
专用长currentPage=1L;
私人长行数;
私人长网页;
私有整数状态;
私有结构实体=新结构();
private Listfabrics=new ArrayList();
//接球手和接球手。
@动作(value=“Fabric”,
结果={
@结果(name=ActionSupport.SUCCESS,location=“Fabric.jsp”),
@结果(name=ActionSupport.INPUT,location=“Fabric.jsp”)},
拦截器={
@InterceptorRef(value=“paramspreparamsstack”,params={“params.acceptParamNames”,“id,currentPage,rowCount,totalPages,message,status”,“validation.ValidateAnotatedMethodOnly”,“true”,“validation.excludeMethods”,“load”})
公共字符串加载()引发异常
{
//在加载页面时调用。
返回ActionSupport.SUCCESS;
}
@操作(value=“FabricPage”,
results={@Result(name=ActionSupport.SUCCESS,location=“Fabric.jsp”,params={“namespace”、“/admin_side”、“actionName”、“Fabric”、“currentPage”、“${currentPage}”),
@结果(name=ActionSupport.INPUT,location=“Fabric.jsp”)},
拦截器={
@InterceptorRef(value=“conversionError”),
@InterceptorRef(value=“paramspreparamsstack”,params={“params.acceptParamNames”,“currentPage”,“validation.validateNotatedMethodOnly”,“true”})
公共字符串页()
{
//在单击页面链接时调用。
返回ActionSupport.SUCCESS;
}
@验证(
所需字符串={
@RequiredStringValidator(fieldName=“fabricName”,type=ValidatorType.FIELD,key=“fabric.name.required”)},
StringLength字段={
@StringLengthFieldValidator(fieldName=“fabricName”,type=ValidatorType.FIELD,minLength=“2”,maxLength=“45”,key=“fabric.name.length”,messageParams={“2”,“45”})
@操作(value=“AddFabric”,
结果={
@结果(name=ActionSupport.SUCCESS,type=“redirectAction”,location=“Fabric.jsp”,params={“namespace”、“/admin_side”、“actionName”、“Fabric”、“currentPage”、“${currentPage}”、“message”、“${message}”、“id”、“${id}”、“status”、“${status}”),
@结果(name=ActionSupport.INPUT,location=“Fabric.jsp”)},
拦截器={
@InterceptorRef(value=“conversionError”),
@InterceptorRef(value=“paramspreparamsstack”,params={”params.acceptParamNames”,“id,fabricId,fabricName,currentPage,rowCount,totalPages,status”,“validation.ValidateAnotatedMethodOnly”,“true”})
})
公共字符串插入()
{
//处理插入和更新操作。
返回ActionSupport.SUCCESS;
}
@操作(value=“EditFabric”,
结果={
@结果(name=ActionSupport.SUCCESS,location=“Fabric.jsp”),
@结果(name=ActionSupport.INPUT,location=“Fabric.jsp”)},
拦截器={
@InterceptorRef(value=“paramspreparamsstack”,params={“params.acceptParamNames”,“id,fabricId,fabricName,currentPage”,“validation.validateAnotatedMethodOnly”,“true”}),
@InterceptorRef(value=“conversionError”)})
公共字符串编辑()
{
//在单击编辑链接时调用。
返回ActionSupport.SUCCESS;
}
@验证(
fieldExpressions={@FieldExpressionValidator(fieldName=“deleteOneRow”,expression=“deleteOneRow==true”,shortCircuit=true,key=“delete.row.reject”)})
@操作(value=“DeleteFabric”,
结果={
@结果(name=ActionSupport.SUCCESS,type=“redirectAction”,location=“Fabric.action”,params={“currentPage”、“${currentPage}”、“message”、“${message}”、“status”、“${status}”),
@结果(name=ActionSupport.INPUT,location=“Fabric.jsp”)},
拦截器={
@InterceptorRef(value=“paramspreparamsstack”,params={“params.acceptParamNames”,“deleteId,deleteOneRow,currentPage,status”,“validation.validateAnotatedMethodOnly”,“true”}),
@InterceptorRef(value=“conversionError”)})
公共字符串deleteSingleRow()
{
//处理单行的删除。
返回ActionSupport.SUCCESS;
}
@验证(
必填字段={
@RequiredFieldValidator(type=ValidatorType.FIELD,fieldName=“chk”,key=“delete.multiple.alert”),
@RequiredFieldValidator(type=ValidatorType.FIELD,fieldName=“deleteMultipleRows”,key=“delete.multiple.confirm”)}
@操作(value=“DeleteFabrics”,
结果={
@结果(name=ActionSupport.SUCCESS,type=“redirectAction”,location=“Fabric.jsp”,params={“namespace”、“/admin_side”、“actionName”、“Fabric”、“currentPage”、“${currentPage}”、“message”、“${message}”、“status”、“${status}”),
@结果(name=ActionSupport.INPUT,location=“Fabric.jsp”)},
拦截器={
@InterceptorRef(value=“paramspreparamsstack”,params={“params.acceptParamNames”,“deleteMultipleRows,chk,currentPage,rowCount,totalPages”,“validation.ValidateAnotatedMethodOnly”,“true”}),
@InterceptorRef(value=“conversionError”)})
公共字符串deleteMultipleRows()
{
@Result(name=ActionSupport.SUCCESS, type="redirectAction", location="Fabric.jsp",
@Result(name=ActionSupport.SUCCESS, location="Fabric.jsp",
@Result(name=ActionSupport.SUCCESS, type="redirectAction", location="Fabric"
interceptorRefs={
            @InterceptorRef(value="paramsPrepareParamsStack"...)})
@Namespace("/")
@InterceptorRef("myCustomStack")
@Results({ @Result(name = "cancel", location = "${previousPageLink}", type = "redirectAction", params = {
 }) })
public class BaseAction extends ActionSupport implements ServletRequestAware, ParameterAware,
SessionAware { 
...
}
@Namespace("/")
@InterceptorRefs({
@InterceptorRef(value = "store", params = {"operationMode", "RETRIEVE"}) })
/*@InterceptorRef("myCustomStack") })*/
@Results({ @Result(name = "success", location = "home.def", type = "tiles")
})
public class HomeAction extends BaseAction implements Preparable {
...
}
<struts>
  <constant name="struts.convention.action.packages" value="com.myapp.action" />
  <constant name="struts.convention.default.parent.package" value="default" />
  <constant name="struts.action.extension" value="action" />
  <constant name="struts.enable.DynamicMethodInvocation" value="false" />
  <constant name="struts.ognl.allowStaticMethodAccess" value="true" />
  <package name="default" namespace="/" extends="tiles-default,json-default">
    <interceptors>
      <interceptor-stack name="myCustomStack">
        <interceptor-ref name="basicStack" />
        <interceptor-ref name="staticParams" />
        <interceptor-ref name="validation">
          <param name="excludeMethods">input,back,cancel,browse</param>
        </interceptor-ref>
        <interceptor-ref name="workflow">
          <param name="excludeMethods">input,back,cancel,browse</param>
        </interceptor-ref>
      </interceptor-stack>
    </interceptors>
  </package>
</struts>