<bdo id='w3JJY'></bdo><ul id='w3JJY'></ul>
    <i id='w3JJY'><tr id='w3JJY'><dt id='w3JJY'><q id='w3JJY'><span id='w3JJY'><b id='w3JJY'><form id='w3JJY'><ins id='w3JJY'></ins><ul id='w3JJY'></ul><sub id='w3JJY'></sub></form><legend id='w3JJY'></legend><bdo id='w3JJY'><pre id='w3JJY'><center id='w3JJY'></center></pre></bdo></b><th id='w3JJY'></th></span></q></dt></tr></i><div id='w3JJY'><tfoot id='w3JJY'></tfoot><dl id='w3JJY'><fieldset id='w3JJY'></fieldset></dl></div>

    <tfoot id='w3JJY'></tfoot>

      <legend id='w3JJY'><style id='w3JJY'><dir id='w3JJY'><q id='w3JJY'></q></dir></style></legend>
      1. <small id='w3JJY'></small><noframes id='w3JJY'>

        struts2 动作中的验证异常

        时间:2023-09-25

            • <small id='QgkUo'></small><noframes id='QgkUo'>

              <tfoot id='QgkUo'></tfoot>

                <bdo id='QgkUo'></bdo><ul id='QgkUo'></ul>
                    <tbody id='QgkUo'></tbody>
                  <i id='QgkUo'><tr id='QgkUo'><dt id='QgkUo'><q id='QgkUo'><span id='QgkUo'><b id='QgkUo'><form id='QgkUo'><ins id='QgkUo'></ins><ul id='QgkUo'></ul><sub id='QgkUo'></sub></form><legend id='QgkUo'></legend><bdo id='QgkUo'><pre id='QgkUo'><center id='QgkUo'></center></pre></bdo></b><th id='QgkUo'></th></span></q></dt></tr></i><div id='QgkUo'><tfoot id='QgkUo'></tfoot><dl id='QgkUo'><fieldset id='QgkUo'></fieldset></dl></div>
                  <legend id='QgkUo'><style id='QgkUo'><dir id='QgkUo'><q id='QgkUo'></q></dir></style></legend>
                  本文介绍了struts2 动作中的验证异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一些 Action 类并尝试添加一个带有验证的表单.但是每次我尝试这样做时都会遇到异常.

                  I have some Action class and try to add a form with validation. But every time when I tried to do it I have got an exception.

                  动作类代码:

                  public void validate() {
                      if (name == null || name.trim().equals("")) {
                          addFieldError("name", "The name is required");
                      }
                      if (surname == null || surname.trim().equals("")) {
                          addFieldError("surname", "Age must be in between 28 and 65");
                      }
                  }
                  

                  表格代码:

                  <s:form action="addnew" method="POST">
                      <s:textfield label="Name: " name="name"/>
                      <s:textfield label="Surname: " name="surname"/>
                      <s:submit/>
                  </s:form>
                  

                  例外:

                  WARNING: Could not find action or result
                  No result defined for action com.app.action.AddClientAction and result input
                      at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:275)
                      at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
                      at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
                      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249)
                      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249)
                      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
                      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
                      at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:546)
                      at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
                      at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
                      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
                      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
                      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
                      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
                      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
                      at java.lang.Thread.run(Thread.java:722)
                  
                  июн 07, 2013 10:52:38 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger error
                  SEVERE: Exception occurred during processing request: No result defined for action com.app.action.AddClientAction and result input
                  No result defined for action com.app.action.AddClientAction and result input
                      at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:373)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:275)
                      at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:265)
                      at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)
                      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:138)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249)
                      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:249)
                      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:191)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:73)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:91)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:252)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:100)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:141)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:145)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:171)
                      at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:98)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:176)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:193)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:187)
                      at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:246)
                      at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
                      at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:546)
                      at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
                      at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
                      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
                      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
                      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
                      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
                      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:606)
                      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
                      at java.lang.Thread.run(Thread.java:722)
                  

                  推荐答案

                  验证框架要求action配置中名为"input"的结果存在,如果出现验证错误(或者你添加了)在 validate() 方法中通过 addActionError()addFieldError()) 然后默认情况下,此结果将在执行之前由操作返回.

                  The validation framework requires the result named "input" in the action configuration exist, if the validation errors occurred ( or you added them in the validate() method via addActionError() and addFieldError()) then by default this result will be returned by the action before its execution.

                  @Action(value = "addnew", results = {
                    @Result(name = "input", location = "/pages/addnew.jsp"),
                  }, interceptorRefs = @InterceptorRef("validationWorkflowStack"))
                  public class AddnewAction extends ActionSupport {
                  

                  结果放在动作注解中,可能有很多结果用逗号分隔,我只保留了一个对验证很重要的结果.引用的拦截器堆栈是处理验证的最小堆栈,它也是默认堆栈的子集.

                  Results are placed inside the action annotation, there could be many results separated by comma, I have remained only one that is important to validation. The referenced interceptor stack is a minimal stack that processes the validation, it's also a subset of the default stack.

                  如果你在action上加注解,方法execute会被调用,否则你需要在方法上加注解.配置动作映射和方法执行有很多可能性.

                  If you put annotation on action then method execute will call, otherwise you need to put the action annotation on the method. There are many possibilities to configure action mapping and method execution.

                  您也可以像 本教程中添加结果输入",操作已映射按照惯例,或使用验证注释来执行验证,如 这个例子.其实我没有得到你需要什么样的注释.

                  You may also add result "input" like in this tutorial, actions are mapped by convention, or use the validation annotations to perform validation like in this example. Actually I didn't get what kind of annotations you need.

                  这篇关于struts2 动作中的验证异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用命名约定插件拒绝直接访问 Struts2 中的 JSP 文件 下一篇:如何在 Struts 2 中使用动态参数更改 ActionForward

                  相关文章

                    <small id='wYtXX'></small><noframes id='wYtXX'>

                    <i id='wYtXX'><tr id='wYtXX'><dt id='wYtXX'><q id='wYtXX'><span id='wYtXX'><b id='wYtXX'><form id='wYtXX'><ins id='wYtXX'></ins><ul id='wYtXX'></ul><sub id='wYtXX'></sub></form><legend id='wYtXX'></legend><bdo id='wYtXX'><pre id='wYtXX'><center id='wYtXX'></center></pre></bdo></b><th id='wYtXX'></th></span></q></dt></tr></i><div id='wYtXX'><tfoot id='wYtXX'></tfoot><dl id='wYtXX'><fieldset id='wYtXX'></fieldset></dl></div>

                      <tfoot id='wYtXX'></tfoot>
                    1. <legend id='wYtXX'><style id='wYtXX'><dir id='wYtXX'><q id='wYtXX'></q></dir></style></legend>
                        <bdo id='wYtXX'></bdo><ul id='wYtXX'></ul>