Struts 2 validate specific action in xml

前端 未结 3 506
鱼传尺愫
鱼传尺愫 2021-01-26 13:30

I want to validate specific method only in action class. Action method is this.

public String add() throws Exception {

         


        
3条回答
  •  半阙折子戏
    2021-01-26 14:04

    Use an action alias: map different methods of an Action to different action aliases in struts.xml, and instead of the single yourAction-validation.xml file, add a yourAction-yourAlias-validation.xml for the validators you want to perform for that method only.

    Read more here.

    EDIT

    No its not validation anything now.

     
        
             
                You cannot leave the aoName address field empty.
             
        
    
    

    name is OraganisationAction-add-validation.xml and put it with action class package. Is there anything to enable validation in struts.xml ?

    If you have a correctly configured (for example the default) Interceptor Stack, validation is already enabled. If you are using a file named OraganisationAction-add-validation.xml, that means that:

    • your action CLASS must be named OraganisationAction.java;
    • your action mapping in struts.xml must be the following:

      
          yourResult.jsp
      
      

    Look for typos, check your Interceptor Stack, and it will work automatically.

提交回复
热议问题