近日在做struts2框架验证中碰到了问题,弄了很久也没解决,希望哪位“大牛”可以帮帮忙@Validations(requiredStrings = {
@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "userDTO.userName", message = "登录名不能为空"),
@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "userDTO.password", message = "密码不能为空") })
public String login()@Validations(requiredStrings = {
@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "userDTO.registUserName", message = "注册名不能为空"),
@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "userDTO.registPassword", message = "注册密码不能为空") })
public String regist()这是我在一个action中写的两个方法,分别对login和regist进行验证,一开始我以为在哪个方法上面写的就是对哪个方法进行验证,但是运行起来发现自己错了,会导致login时调用regist的方法,如果用@SkipValidation的话,就不会对表单提交的数据进行验证,但是实际情况是login需要执行login的验证,regist需要执行regist的验证,两个表单在一个页面中,后来在网上查到可以对action中的方法配置拦截器,就将login的代码改成如下:@Validations(requiredStrings = {
@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "userDTO.userName", message = "登录名不能为空"),
@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "userDTO.password", message = "密码不能为空") })
@Action(value="User_login",interceptorRefs = @InterceptorRef(value = "defaultStack", params = {
"validation.validateAnnotatedMethodOnly", "true",
"validation.excludeMethods", "regist" }))
public String login()这里User_login是actionName,对应的method是login,对这个方法进行配置拦截器让他可以在对login进行验证的时候不对regist方法做验证,不过在运行的时候,没有效果。不知道哪里出问题了?
我也试过@Action(value="User_login",interceptorRefs = @InterceptorRef(value = "validation", params = {
"validateAnnotatedMethodOnly", "true",
"excludeMethods", "regist" }))这么写,可是也没作用。
使用xml,用ActionClass-ActionAlias-validation.xml可以解决问题,不过我现在希望用annotation解决,既然annotation要实现的是零配置,我相信用annotation也可以解决,不过不知道错在哪里,希望哪位仁兄可以帮下忙,谢谢了!!
@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "userDTO.userName", message = "登录名不能为空"),
@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "userDTO.password", message = "密码不能为空") })
public String login()@Validations(requiredStrings = {
@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "userDTO.registUserName", message = "注册名不能为空"),
@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "userDTO.registPassword", message = "注册密码不能为空") })
public String regist()这是我在一个action中写的两个方法,分别对login和regist进行验证,一开始我以为在哪个方法上面写的就是对哪个方法进行验证,但是运行起来发现自己错了,会导致login时调用regist的方法,如果用@SkipValidation的话,就不会对表单提交的数据进行验证,但是实际情况是login需要执行login的验证,regist需要执行regist的验证,两个表单在一个页面中,后来在网上查到可以对action中的方法配置拦截器,就将login的代码改成如下:@Validations(requiredStrings = {
@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "userDTO.userName", message = "登录名不能为空"),
@RequiredStringValidator(type = ValidatorType.SIMPLE, fieldName = "userDTO.password", message = "密码不能为空") })
@Action(value="User_login",interceptorRefs = @InterceptorRef(value = "defaultStack", params = {
"validation.validateAnnotatedMethodOnly", "true",
"validation.excludeMethods", "regist" }))
public String login()这里User_login是actionName,对应的method是login,对这个方法进行配置拦截器让他可以在对login进行验证的时候不对regist方法做验证,不过在运行的时候,没有效果。不知道哪里出问题了?
我也试过@Action(value="User_login",interceptorRefs = @InterceptorRef(value = "validation", params = {
"validateAnnotatedMethodOnly", "true",
"excludeMethods", "regist" }))这么写,可是也没作用。
使用xml,用ActionClass-ActionAlias-validation.xml可以解决问题,不过我现在希望用annotation解决,既然annotation要实现的是零配置,我相信用annotation也可以解决,不过不知道错在哪里,希望哪位仁兄可以帮下忙,谢谢了!!
解决方案 »
- java代码导入excel表格里的数据!
- textarea中的字段内容太长则无法提交的问题?
- 新人入驻JAVA WEB开发社区,请教高手们如今用什么版本的SDK+Tomcat+eclipe+MyEclipe?
- tomcat配置jndi问题
- 谁做过流程定义方面的进来给电建议或者例子指导下!
- 上传附件错误,存储oracle的blob字段报错
- Varchar(4000)的字段揷入1900个汉字时提示" 数据大小超出此类型的最大值"?高分相送
- 一个从servlet跳转到jsp页面并传对象的问题?
- 如何在XSL文件中使用像JSP的Include方法?
- java.lang.NullPointerException错误是什么原因?
- 服务端输出js脚本'<script>'被转义<script>
- 求助````
@Validation了吗?