代码之家  ›  专栏  ›  技术社区  ›  Jigar Shah

将参数传递到struts2中不起作用

  •  0
  • Jigar Shah  · 技术社区  · 15 年前

    我将结果配置如下:它是我的自定义结果类型。

    <result-types>
        <result-type name="myBytesResult" class="blahblah.MyBytesResult" />
    </result-types>
    
    
    <action name="myAction" class="blahblah.MyAction">
        <result name="success" type="myBytesResult">
           <param name="pptId">${pptId}</param>
        </result>
    </action>
    

    我的结果有pptId的setter/getter,MyAction也有pptId的setter/getter。但是当我签入我的结果时,它没有设置pptId(我得到的${pptId}是结果中的字符串)。它似乎没有从行动中获得动力。

    为什么会这样?

    我的行为准则

    public String doDefault() {
           System.out.println("Default Called");
           setPptId("MyPpt");
          return "success";
      }
    
      public byte[] getMyImageInBytes() throws Exception { 
           try {
                    //.....
           } catch (Exception e) {
    
           }
           return null;
    
      }
    
    
    public String getContentType() {
        return contentType;
    }
    
    public void setContentType(String contentType) {
        this.contentType = contentType;
    }
    
    public String getPptId() {
        return this.pptId;
    }
    
    public void setPptId(String pptId) {
        this.pptId = pptId;
    }
    

    MyBytesResult公司

    private String contentType;
    
    private String pptId;
    
    
    public void execute(ActionInvocation invocation) throws Exception {
        HttpServletResponse response = ServletActionContext.getResponse();
             //...Some more code for settign response
        System.out.println("pt Id[" + this.pptId + "]");
    
    }
    
    
    public String getContentType() {
        return contentType;
    }
    
    
    public void setContentType(String contentType) {
        this.contentType = contentType;
    }
    
    
    public String getPptId() {
        return pptId;
    }
    
    
    public void setPptId(String pptId) {
        this.pptId = pptId;
    }
    
    1 回复  |  直到 15 年前
        1
  •  0
  •   Steven Benitez    15 年前

    更新的答案

    所以,经过一番挖掘,这似乎是真的工作正常。如果有必要,结果有责任将传入数据作为OGNL表达式进行计算。这就是重定向和http头结果的工作方式。可以根据自定义结果中的堆栈分析值,如下所示:

    String resolvedPptId = TextParseUtil.translateVariables(pptId, stack)
    

    从Javadoc translateVariables :

    转换中${…}和%{…}的所有实例 expression 调用{@link ValueStack\findValue(java.lang.String)}返回的值。如果一个项目不能 在堆栈上找到(返回空值),则整个变量${…}不是 显示,就像项在堆栈上但返回空字符串一样。