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

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

      • <bdo id='wEGQI'></bdo><ul id='wEGQI'></ul>
      <tfoot id='wEGQI'></tfoot>

      使用 param 标签抑制空参数

      Suppress empty parameters using param tag(使用 param 标签抑制空参数)
        <bdo id='0z5Pe'></bdo><ul id='0z5Pe'></ul>
      • <tfoot id='0z5Pe'></tfoot>

        <small id='0z5Pe'></small><noframes id='0z5Pe'>

              <tbody id='0z5Pe'></tbody>

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

                本文介绍了使用 param 标签抑制空参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我编写了用于许多操作的 JSP.它有一个参数链接

                I have written JSP that I used with many actions. It has a link with parameters

                链接:

                <s:a namespace="/some" action="view">
                  <s:param name="purpose" value="%{purpose}"/>
                  <s:param name="type" value="%{type}"/>
                  <s:property value="%{name}"/>
                </s:a>
                

                动作类:

                public class ViewAction extends ActionSupport {
                
                  private Long purpose;
                  private Long type;
                  private String name;
                
                  public Long getPurpose() {
                    return purpose;
                  }
                
                  public void setPurpose(Long purpose) {
                    this.purpose = purpose;
                  }
                
                  public Long getType() {
                    return type;
                  }
                
                  public void setType(Long type) {
                    this.type = type;
                  }
                
                  public String getName() {
                    return name;
                  }
                
                  public void setName(String name) {
                    this.name = name;
                  }
                }
                

                通常我会初始化两个参数,但有时一个参数是null.所以,链接是用 href 生成的,比如

                Usually I initialize both parameters, but sometimes one parameter is null. So, the link is generated with href like

                /context/some/view?purpose=1&type=
                

                但我想删除 &type=

                我尝试了 Param 示例.

                <s:a namespace="/some" action="view">
                  <s:param name="purpose" value="%{purpose}"/>
                  <s:param name="type" value="%{type}"/>
                  <s:property value="%{name}"/>
                  <s:param name="suppressEmptyParameters" value="true"/>
                </s:a>
                

                但是没用

                我也试过了

                <s:a namespace="/some" action="view">
                  <s:param name="purpose" value="%{purpose}"/>
                  <s:param name="type" value="%{type}" suppressEmptyParameters="true"/>
                  <s:property value="%{name}"/>
                </s:a>
                

                我得到了

                java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.String
                    at org.apache.struts2.components.Param.end(Param.java:129)
                    at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:42)
                

                如何解决这个问题?

                推荐答案

                那行 <s:param name="suppressEmptyParameters" value="true"/> 没有意义,并且应该从 <s:param> 文档中删除.

                Well that line <s:param name="suppressEmptyParameters" value="true"/> doesn't make sense, and it should be removed from the <s:param> docs.

                <s:param name="type" value="%{type}" suppressEmptyParameters="true"/> 是抑制空参数的正确方法,但它不起作用由于错误 WW-4275 而不是 String-s.

                The <s:param name="type" value="%{type}" suppressEmptyParameters="true"/> is correct way of suppressing empty parameters and it isn't working with not String-s because of the bug WW-4275.

                同时,在下一个版本发布之前,您可以使用toString()方法来避免ClassCastException异常.

                Meanwhile, until the next version is released, you can use toString() method to avoid ClassCastException exception.

                <s:param name="type" value="type.toString()" suppressEmptyParameters="true"/>
                

                这篇关于使用 param 标签抑制空参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

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

                <tfoot id='2y61t'></tfoot>

                <small id='2y61t'></small><noframes id='2y61t'>

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

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