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

    <legend id='Sthox'><style id='Sthox'><dir id='Sthox'><q id='Sthox'></q></dir></style></legend>
    <tfoot id='Sthox'></tfoot>
      <bdo id='Sthox'></bdo><ul id='Sthox'></ul>
      1. <small id='Sthox'></small><noframes id='Sthox'>

      2. 通过重定向到操作来保留所有请求参数

        Preserving all request parameters through a redirect to an Action(通过重定向到操作来保留所有请求参数)

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

                <tfoot id='2kAwF'></tfoot>
                  <bdo id='2kAwF'></bdo><ul id='2kAwF'></ul>
                    <tbody id='2kAwF'></tbody>
                  <legend id='2kAwF'><style id='2kAwF'><dir id='2kAwF'><q id='2kAwF'></q></dir></style></legend>
                  本文介绍了通过重定向到操作来保留所有请求参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  更新页面中的记录后,我需要使用更新的消息(成功/失败)填充记录.这两个动作都来自同一页面.我已将代码添加为,完成更新操作后将结果类型添加为链并显示成功消息.但是当我们在更新操作完成后立即(第一次)单击搜索时,它并没有消失.帮助我在单击搜索操作时清除消息.

                  I need to populate the records with updated message (success / failure)after updating the records in the page. both the actions are from same page. I have added the code as, After completing Update action added the result type as Chain and it shows success message. But it is not disappearing when we click on Search immediately(first time) after update action completes. Help me to clear the message while clicking on search action.

                  由于上述问题,我在结果类型中使用了重定向选项.但我可以在重定向操作中获取请求参数.除了硬编码之外,还有什么方法可以在重定向操作中获取所有请求参数?

                  Due to above issue i used redirect option in result type. But i could get the request parameters in redirected action. is there any way to get all request parametrs in redirected action other than hardcoding it?

                  <interceptor-stack name="storeStack">
                      <interceptor-ref name="defaultStack" />
                      <interceptor-ref name="store">
                          <param name="operationMode">STORE</param>
                      </interceptor-ref>
                  </interceptor-stack>
                  
                  <interceptor-stack name="retrieveStack">
                      <interceptor-ref name="defaultStack" />
                      <interceptor-ref name="store">
                          <param name="operationMode">RETRIEVE</param>
                      </interceptor-ref>
                  </interceptor-stack>
                  
                  <action name="hierarchySaveMap" method="updateHierarchyMap"
                      class="com.cotyww.bru.web.action.master.HierarchyUpdateAction">
                      <interceptor-ref name="storeStack" />
                      <result name="success" type="redirectAction">
                          <param name="actionName">hierUpdateMDA</param>
                          <param name="parse">true</param>
                      </result>
                      <result name="input" type="tiles">hierarchyUpdate{1}</result>
                      <result name="error" type="tiles">hierarchyUpdate{1}</result>
                  </action>
                  

                  有没有办法在 struts.xml 中不进行硬编码而将参数动态发送到下一个操作?

                  Is there a way to send the parameters to next action dynamically without hardcoding in struts.xml?

                  推荐答案

                  你不能用 redirectAction 来做到这一点,其中参数名称和值可以是动态的,但参数的数量必须是硬编码的,例如

                  You can't do it with a redirectAction, where parameters names and values can be dynamic but the number of parameters must be hard-coded, like

                  <result name="success" type="redirectAction">
                      <param name="actionName">hierUpdateMDA</param>
                      <param name="${paramName1}">${paramValue1}</param>
                      <param name="${paramName2}">${paramValue2}</param>
                      <param name="${paramName3}">${paramValue3}</param>
                  

                  但是您可以使用 redirect 结果(通常用于重定向到非操作 URL)来做到这一点.

                  But you can do it with a redirect result (that is generally used to redirect to non-action URLs).

                  基本上,您只需要在 Struts 配置中指定命名空间和操作名称(它们也可以是动态的,TBH),以及表示 QueryString 的动态参数.

                  Basically, you need to specify only the namespace and the action name (and they could be dynamic too, TBH) in Struts configuration, and a dynamic parameter representing the QueryString.

                  然后在第一个 Action(或 BaseAction)中,您需要一个方法来获取 Parameter Map,循环遍历每个参数(及其每个值),对它们进行 URLEncode 并返回挂载的 QueryString.而已.

                  Then in the first Action (or in a BaseAction), you need a method to get the Parameter Map, loop through each parameter (and each one of its values), URLEncode them and return the mounted QueryString. That's it.

                  这将适用于表单数据 (POST)、查询参数(通常是 GET)或两者(带有表单数据 QueryString 的 POST),并且它是 URL 安全的.

                  This will work with form data (POST), query parameters (generally GET) or both (POST with form data and QueryString), and it's URL safe.

                  Struts 配置

                  <package name="requestGrabber" namespace="cool" extends="struts-default">
                      <action name="source" class="org.foo.bar.cool.RequestGrabberAction" 
                            method="source">
                          <result type="redirect">                
                              <param name="location">/cool/target.action${queryParameters}</param>
                          </result>
                      </action>
                      <action name="target" class="org.foo.bar.cool.RequestGrabberAction" 
                            method="target">
                          <result name="success">/cool/requestGrabber.jsp</result>
                      </action>
                  </package>
                  

                  org.foo.bar.cool.RequestGrabberAction.java(动作类)

                  org.foo.bar.cool.RequestGrabberAction.java (Action classes)

                  package org.foo.bar.cool;
                  
                  import javax.servlet.http.HttpServletRequest;
                  import java.io.UnsupportedEncodingException;
                  import java.net.URLEncoder;
                  import java.util.Enumeration;
                  import org.apache.struts2.interceptor.ServletRequestAware;
                  import com.opensymphony.xwork2.ActionSupport;
                  
                  @SuppressWarnings("serial")
                  public class RequestGrabberAction extends ActionSupport 
                                                 implements ServletRequestAware {
                  
                      private HttpServletRequest request; 
                      public void setServletRequest(HttpServletRequest request){ 
                          this.request = request;
                      }
                  
                      public String source(){
                          System.out.println("Source Action executed");
                          return SUCCESS;
                      }
                  
                      public String target(){     
                          System.out.println("Target Action executed");
                          return SUCCESS;
                      }
                  
                  
                      public String getQueryParameters() throws UnsupportedEncodingException {
                          String queryString = "";
                  
                          // Get parameters, both POST and GET data
                          Enumeration<String> parameterNames = request.getParameterNames();
                  
                          // Loop through names
                          while (parameterNames.hasMoreElements()) {            
                              String paramName = parameterNames.nextElement();
                              // Loop through each value for a single parameter name
                              for (String paramValue : request.getParameterValues(paramName)) {
                                  // Add the URLEncoded pair
                                  queryString += URLEncoder.encode(paramName, "UTF-8") + "="
                                               + URLEncoder.encode(paramValue,"UTF-8") + "&";
                              } 
                          }
                  
                          // If not empty, prepend "?" and remove last "&"
                          if (queryString.length()>0){  
                              queryString = "?" 
                                          + (queryString.substring(0,queryString.length()-1));
                          }
                  
                          return queryString;
                      }
                  
                  }
                  

                  /cool/requestGrabber.jsp

                  <%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
                  <%@ taglib prefix="s" uri="/struts-tags"%>
                  
                  <!doctype html>
                  <html>
                      <head>
                          <title>Request Grabber</title>
                      </head>
                      <body>
                          QueryString = <s:property value="queryParameters" />
                          <s:form action="source" namespace="/cool">
                              <s:textfield name="foo" value="%{#parameters.foo}" />
                              <s:textfield name="bar" value="%{#parameters.bar}" />
                              <s:submit />
                          </s:form>       
                      </body>
                  </html>
                  

                  享受

                  这篇关于通过重定向到操作来保留所有请求参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的游戏框架.有什么建议吗?)

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

                  <legend id='oiM12'><style id='oiM12'><dir id='oiM12'><q id='oiM12'></q></dir></style></legend>

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

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

                        • <tfoot id='oiM12'></tfoot>