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

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

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

          <bdo id='y2SnF'></bdo><ul id='y2SnF'></ul>

        如何将参数从 JSP 传递到 Struts 2 动作

        How to pass a parameter from JSP to Struts 2 action(如何将参数从 JSP 传递到 Struts 2 动作)

            <tbody id='ZwJNZ'></tbody>
            1. <small id='ZwJNZ'></small><noframes id='ZwJNZ'>

                <bdo id='ZwJNZ'></bdo><ul id='ZwJNZ'></ul>
                <tfoot id='ZwJNZ'></tfoot>
                <i id='ZwJNZ'><tr id='ZwJNZ'><dt id='ZwJNZ'><q id='ZwJNZ'><span id='ZwJNZ'><b id='ZwJNZ'><form id='ZwJNZ'><ins id='ZwJNZ'></ins><ul id='ZwJNZ'></ul><sub id='ZwJNZ'></sub></form><legend id='ZwJNZ'></legend><bdo id='ZwJNZ'><pre id='ZwJNZ'><center id='ZwJNZ'></center></pre></bdo></b><th id='ZwJNZ'></th></span></q></dt></tr></i><div id='ZwJNZ'><tfoot id='ZwJNZ'></tfoot><dl id='ZwJNZ'><fieldset id='ZwJNZ'></fieldset></dl></div>
              • <legend id='ZwJNZ'><style id='ZwJNZ'><dir id='ZwJNZ'><q id='ZwJNZ'></q></dir></style></legend>
                  本文介绍了如何将参数从 JSP 传递到 Struts 2 动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个应用程序,我想在每次按下该项目的按钮时将项目 id 传递给操作.

                  I have an application and I want to pass item id to the action every time the button for that item is pressed.

                  <s:submit  value="addToCart" action="addToCart" type="submit">
                  <s:param name="id" value="%{#cpu.id}" />
                  </s:submit>
                  

                  行动:

                  public class ProductsCPU extends BaseAction implements Preparable, SessionAware {
                  private static final long serialVersionUID = 2124421844550008773L;
                  
                  private List colors = new ArrayList<>();
                  private List cpus;
                  private String id;
                  
                  public String getId() {
                      return id;
                  }
                  
                  public void setId(String id) {
                      this.id = id;
                  }
                  

                  当我将 id 打印到控制台时,它具有 null 值.有什么问题?

                  When I print id to console, it has the null value. What is the problem?

                  推荐答案

                  问题是你不能用 s:param 标签参数化 s:submit 标签在您的代码中使用 submit 标签正文中的 param 标签.

                  The problem is that you can't parametrize s:submit tag with s:param tag like in your code using param tag in the body of submit tag.

                  您也不想添加 hidden 字段,因为您有多个值提交给操作.这是因为许多隐藏字段以相同的名称呈现.您可以只使用一个字段并在提交表单之前更新其值.

                  You also don't want to add hidden field because you got multiple values submitted to the action. This is because many hidden fields are rendered with the same name. You could use only one field and update its value before submitting a form.

                  您可能使用了错误的标签来将参数传递给操作.您可以使用锚标记并使用 param 标记对其进行参数化.

                  Probably you have used wrong tag to pass a parameter to the action. You can use anchor tag and parametrize it with param tag.

                  第二种方法是使用javascript修改action属性.通过这种方式,您还可以使用 button 标记.

                  The second way is to use javascript to modify action attribute. In this way you can also use a button tag.

                  不推荐第三种方式,因为它需要每个链接使用多个表单.这样就可以直接给表单动作属性添加参数了.

                  Third way is not recommended because it requires to use multiple forms one per each link. In this way you add a parameter to the form action attribute directly.

                  下面是上述选项的代码.

                  Below is the code for the options mentioned above.

                  <s:form name="myForm13" namespace="/" action="save?message=Hello param 3" theme="simple">
                    <br/><s:a cssClass="btn btn-primary" action="test"><s:param name="message">Hello param 1</s:param>&nbsp;&nbsp;&nbsp;Go&nbsp;&nbsp;&nbsp;</s:a>
                    <br/><s:a href="#" cssClass="btn btn-warning" onclick="myForm13.action='test?message=Hello param 2';myForm13.submit()">Submit</s:a>
                    <br/><s:submit cssClass="btn btn-danger" action="test"/>    
                  </s:form>
                  

                  这篇关于如何将参数从 JSP 传递到 Struts 2 动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

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

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

                  <tfoot id='D8zhK'></tfoot>

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

                      • <bdo id='D8zhK'></bdo><ul id='D8zhK'></ul>

                              <tbody id='D8zhK'></tbody>