<tfoot id='Sv9h7'></tfoot>
  • <small id='Sv9h7'></small><noframes id='Sv9h7'>

  • <legend id='Sv9h7'><style id='Sv9h7'><dir id='Sv9h7'><q id='Sv9h7'></q></dir></style></legend>
      <bdo id='Sv9h7'></bdo><ul id='Sv9h7'></ul>

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

      1. 在 Prepare() 方法中找不到高级通配符映射参数

        Advanced Wildcard Mappings Parameters not found in Prepare() method(在 Prepare() 方法中找不到高级通配符映射参数)

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

        • <bdo id='XbmUV'></bdo><ul id='XbmUV'></ul>
              <tbody id='XbmUV'></tbody>

                1. <tfoot id='XbmUV'></tfoot>

                  <i id='XbmUV'><tr id='XbmUV'><dt id='XbmUV'><q id='XbmUV'><span id='XbmUV'><b id='XbmUV'><form id='XbmUV'><ins id='XbmUV'></ins><ul id='XbmUV'></ul><sub id='XbmUV'></sub></form><legend id='XbmUV'></legend><bdo id='XbmUV'><pre id='XbmUV'><center id='XbmUV'></center></pre></bdo></b><th id='XbmUV'></th></span></q></dt></tr></i><div id='XbmUV'><tfoot id='XbmUV'></tfoot><dl id='XbmUV'><fieldset id='XbmUV'></fieldset></dl></div>
                  <legend id='XbmUV'><style id='XbmUV'><dir id='XbmUV'><q id='XbmUV'></q></dir></style></legend>
                  本文介绍了在 Prepare() 方法中找不到高级通配符映射参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  来自文档:Struts2 的高级通配符映射:

                  高级通配符

                  从 2.1.9+ 开始可以在动作中定义正则表达式名称.要使用这种形式的通配符,以下常量必须是设置:

                  From 2.1.9+ regular expressions can be defined defined in the action name. To use this form of wild card, the following constants must be set:

                  <constant name="struts.enable.SlashesInActionNames" value="true"/> 
                  <constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
                  <constant name="struts.patternMatcher" value="regex" />
                  

                  正则表达式可以有两种形式,最简单的一种是{FIELD_NAME},在这种情况下,字段中包含 FIELD_NAME操作将填充匹配的文本,例如:

                  The regular expressions can be in two forms, the simplest one is {FIELD_NAME}, in which case the field with the FIELD_NAME in the action will be populated with the matched text, for example:

                  <package name="books" extends="struts-default" namespace="/">
                      <action name="/{type}/content/{title}" class="example.BookAction">
                          <result>/books/content.jsp</result>
                      </action> 
                  </package>
                  

                  在本例中,如果网址 /fiction/content/Frankenstein 是请求时,BookAction 的字段type"将设置为fiction",并且字段title"将设置为Frankenstein".

                  In this example, if the url /fiction/content/Frankenstein is requested, BookAction's field "type" will be set to "fiction", and the field "title" will be set to "Frankenstein".

                  这绝对很棒,如果您在常规 Action 方法(如 execute())中读取这些变量,则效果很好.

                  This is absolutely great, and works fine if you read those variables in a regular Action method, like execute().

                  如果你尝试从 prepare() 方法中读取它们,它们是 null,因为 PrepareInterceptor 在其他负责设置参数的拦截器之前运行;解决此问题的常用方法是使用适当的拦截器堆栈来获取执行 prepare() 方法时已填充的参数...

                  If you try to read them from the prepare() method, they are null, because the PrepareInterceptor runs before the other Interceptors responsibles for setting the parameters; the usual way to resolve this issue is to use the apposite Interceptor Stack to get the parameters already populated when executing the prepare() method...

                  来自文档:ParamsPrepareParamStack

                  <!-- An example of the paramsPrepareParams trick. This stack
                       is exactly the same as the defaultStack, except that it
                       includes one extra interceptor before the prepare interceptor:
                       the params interceptor.
                  
                       This is useful for when you wish to apply parameters directly
                       to an object that you wish to load externally (such as a DAO
                       or database or service layer), but can't load that object
                       until at least the ID parameter has been loaded. By loading
                       the parameters twice, you can retrieve the object in the
                       prepare() method, allowing the second params interceptor to
                       apply the values on the object. -->
                  

                  这适用于来自页面的参数,但它不适用于高级通配符设置的参数.它们仍然为空.

                  This works great for parameters coming from the page, but it does not work for the parameters set by Advanced Wildcards. They are still null.

                  如何解决这个问题?

                  推荐答案

                  ParametersInterceptor (就像那些来自 JSP 的),但 由 StaticParametersInterceptor.
                  要有他们填写了 prepare() 方法,必须应用 paramsPrepareParamsStack 相同的技巧.
                  由于没有一个开箱即用的拦截器堆栈,你必须定义它.
                  defaultStack开始,我们应该创建一个像这样堆叠:

                  That parameters are not set by the ParametersInterceptor (like those coming from the JSP), but by the StaticParametersInterceptor.
                  To have them filled in the prepare() method, the same trick of the paramsPrepareParamsStack must be applied.
                  Since there is not an Interceptor Stack that does that out-of-the-box, you must define it.
                  Starting from the defaultStack, we should create a Stack like this:

                  <interceptor-stack name="allYourParamsAreBelongToUsStack">
                      <interceptor-ref name="exception"/>
                      <interceptor-ref name="alias"/>
                      <interceptor-ref name="servletConfig"/>
                      <interceptor-ref name="i18n"/>
                   <!-- THE TRICK: NOW PREPARE() WILL FIND EVERYTHING SET -->     
                      <interceptor-ref name="staticParams"/>
                      <interceptor-ref name="actionMappingParams"/>
                      <interceptor-ref name="params">
                          <param name="excludeParams">dojo..*,^struts..*,^session..*,^request..*,^application..*,^servlet(Request|Response)..*,parameters...*</param>
                      </interceptor-ref>
                   <!-- END OF THE TRICK -->
                      <interceptor-ref name="prepare"/>
                      <interceptor-ref name="chain"/>
                      <interceptor-ref name="scopedModelDriven"/>
                      <interceptor-ref name="modelDriven"/>
                      <interceptor-ref name="fileUpload"/>
                      <interceptor-ref name="checkbox"/>
                      <interceptor-ref name="multiselect"/>
                      <interceptor-ref name="staticParams"/>
                      <interceptor-ref name="actionMappingParams"/>
                      <interceptor-ref name="params">
                          <param name="excludeParams">dojo..*,^struts..*,^session..*,^request..*,^application..*,^servlet(Request|Response)..*,parameters...*</param>
                      </interceptor-ref>
                      <interceptor-ref name="conversionError"/>
                      <interceptor-ref name="validation">
                          <param name="excludeMethods">input,back,cancel,browse</param>
                      </interceptor-ref>
                      <interceptor-ref name="workflow">
                          <param name="excludeMethods">input,back,cancel,browse</param>
                      </interceptor-ref>
                      <interceptor-ref name="debugging"/>
                  </interceptor-stack>
                  

                  注意:ActionMappingParams 不是必需的,只是为了将来使用.

                  Note: ActionMappingParams is not needed, just included for future uses.

                  如果您发现与此相关的任何问题,请发表评论.AFAIK,它完美无瑕.

                  Please comment in case you discover any problem related to this. AFAIK, it works flawlessly.

                  这篇关于在 Prepare() 方法中找不到高级通配符映射参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                  Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                  About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                  What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                  Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                  Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)
                  1. <tfoot id='DVzsC'></tfoot>
                    <i id='DVzsC'><tr id='DVzsC'><dt id='DVzsC'><q id='DVzsC'><span id='DVzsC'><b id='DVzsC'><form id='DVzsC'><ins id='DVzsC'></ins><ul id='DVzsC'></ul><sub id='DVzsC'></sub></form><legend id='DVzsC'></legend><bdo id='DVzsC'><pre id='DVzsC'><center id='DVzsC'></center></pre></bdo></b><th id='DVzsC'></th></span></q></dt></tr></i><div id='DVzsC'><tfoot id='DVzsC'></tfoot><dl id='DVzsC'><fieldset id='DVzsC'></fieldset></dl></div>

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

                        <tbody id='DVzsC'></tbody>
                      • <bdo id='DVzsC'></bdo><ul id='DVzsC'></ul>

                          1. <legend id='DVzsC'><style id='DVzsC'><dir id='DVzsC'><q id='DVzsC'></q></dir></style></legend>