struts validation occurring when page loads instead of on submit

前端 未结 3 962
梦如初夏
梦如初夏 2021-01-23 06:07

Please forgive me; I am sort of new to struts. I am having an issue where my validation is occurring when the page loads instead of when i actually submit my form. I have been

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-23 06:25

    As nmc said, validation fires for the action, and that is what is causing the validation to occur. However, you can still do this without splitting it into two different actions.

    First, you could fix this by getting rid of the init method, and just using input - so your initial url would be inputTest instead of initTest. The validation interceptor by default does not fire on the input method. This is how it is usually handled, and how I lay out all of my actions.

    If you are set on using init, you can actually specify to the validation interceptor which methods to exclude from validation. You could change your xml to look like this:

        
            
                init,input
             
            jsp/index.jsp
            jsp/index.jsp
            jsp/results.jsp
    
    

    Using this xml simply tells the validation interceptor to not fire for the init or input methods.

    Just a couple of different solutions to keep you using just one action class.

提交回复
热议问题