Exception Handling in Struts 1 ActionForm

I am working on an old web application that uses Struts 1.1. To do business validations (complex validations associated with several form properties and backend service calls), I wrote an ActionForm implementation that calls a chain of validators in the ActionForm.validate method.

The validator chain is implemented using the commons chain. Everything is fine, except that when an exception occurs in ActionForm.validate, it is not caught by the struts exception handler, instead, a stack is displayed on the screen. The struts exception handler does not understand that

In any case, to avoid stacktrace on the page and propagate the exception to the struts exception handler?

thank

+3
source share
1 answer

It might be best if validators don't throw exceptions at all. Validations are checking user inputs against restrictions such as minChars, maxChars, strength / password verification, email syntactic correctness, isNumber, etc. If the validator fails, it should only return false - never throw an exception. See Examples at http://struts.apache.org/1.2.4/userGuide/dev_validator.html

If your validator calls backend functions ... something is wrong - I think. The validator should only add field errors.

(, / ) , struts ( ) . , (UserNotLoggedInException).

+1

Source: https://habr.com/ru/post/1759235/


All Articles