作为基于XML的验证的补充,您还可以应用基于注释的配置.这仅是服务器端验证,客户端验证是通过Struts标记应用于启用了浏览器的javascript的,该标记用于将验证内容呈现到要验证的页面上.所有这些概念都不适用于需要身份验证的操作(除非将身份验证拦截器应用于该操作).如果您使用JAAS身份验证,则应考虑采取措施来实现 PrincipalAware 或使用 roles 拦截器将访问限制为检查 isUserInRole() .您可以使用 Action.如果未像是否有一种无需使用 struts.xml即可重定向到另一个动作类的方法 示例.I don't understand conception of Struts2 validation in next case :My application consists of 2 actions:login.actiondrive.actionI can run drive.action from browser command line without filling user and password in login.actionHow can I implement validation code which prevents the run of drive.action from command line if user hasn't successfully filled user and password in login.action? 解决方案It is simple, you map the validators to the fields via the validation configuration file, or via annotations. Then apply a validation interceptor to the action via referencing it explicitly or implicitly via the interceptor stack, custom stack or defaultStack.When validation started it invokes the validation manager to perform actual validation and save errors to the ValidationAware action.Your action should implement this interface, or just extend the ActionSupport where it's already implemented, to save the errors. Then workflow interceptor checks for those errors and if found any of them redirect to the INPUT result, if no errors found the action invocation is executed. You may also add a programmatic validation to the action by implementing Validateable interface, which ActionSupport is implemented by default, hence to override the validate() method(s).As a supplement to XML based validation you could also apply annotation based configuration. This only the server-side validation, the client-side validation applied to the browser enabled javascript via Struts tags used for rendering a validation content to the page being validated.All of this concept is not applicable to the action which requires authentication (unless the authentication interceptor is applied to the action). If you use JAAS authentication, then you should consider your action to implement PrincipalAware or use roles interceptor to restrict access to the action which checks the isUserInRole(). You may use Action.LOGIN result to return to the login page in authentication interceptor if the user is not authenticated like in Is there a way to redirect to another action class without using on struts.xml example. 这篇关于Struts 2中对验证概念的理解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
05-28 00:46
查看更多