使用param标记抑制空参数

我编写了JSP,我使用了许多操作。 它有一个参数链接

链接:

     

动作类:

 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生成的

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

但我想删除&type=

我尝试了Param例子中的一个例子 。

       

但它不起作用

我也试过了

      

我得到了

 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) 

如何解决这个问题呢?

那行没有意义,它应该从 docs中删除。

是抑制空参数的正确方法,由于WW-4275的错误,它不能用于String-s 。

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