【问题标题】:Struts2: values from action are not seen in jsp, but they are seen in the javascript code from jspStruts2:在jsp中看不到来自action的值,但在jsp的javascript代码中可以看到它们
【发布时间】:2012-12-03 13:24:06
【问题描述】:

实际上,我有一个带有吸气剂的变量。

private String myActionVariable = "predefined....";
public String getMyActionVariable () {
    return myActionVariable;
}

在jsp中,我尝试以这种方式使用我的变量:

<input type="button" class="styledButton" 
       onclick="javascript: doAjax('myActionName',false);" 
       value="${myActionVariable}"

但它没有显示。但是,如果我从同一个 jsp 文件中包含的 javascript 代码中输出此变量:

alert (${myActionVariable})

我会得到它的价值....

有什么想法吗? ...

【问题讨论】:

    标签: java html jsp struts2 action


    【解决方案1】:

    您可以使用标准的&lt;input/&gt; HTML 标记和&lt;s:property /&gt; Struts2 标记作为值,如下所示:

    <input type="button" class="styledButton" 
           onclick="javascript:doAjax('myActionName',false);" 
           value="<s:property value="%{myActionVariable}"/>"/>
    

    或者像这样直接使用 Struts2 Tag:

    <s:submit type="button" cssClass="styledButton" 
              onclick="javascript: doAjax('myActionName',false);" 
              value="%{myActionVariable}" />
    

    请注意,使用 Struts2 Tag,class 属性变为 cssClass(并且style 变为 cssStyle),并且 %{} 是正确的 OGNL 语法,而不是 ${}(即 JSTL语法)


    编辑:使用 Struts2 时,忘记 JSTL,您将不再需要它们。

    【讨论】:

      【解决方案2】:

      你应该使用 struts2 标签。

      <input type="button" class="styledButton" onclick="javascript: doAjax('myActionName',false);" value="${myActionVariable}">
      

      代替这个,使用

      <s:submit type="button" cssClass="styledButton" onClick="javascript: doAjax('myActionName',false);" value= "myActionVariable" />
      

      【讨论】:

      • 你不能在另一个 Struts2 标签内使用一个 Struts2 标签(在这种情况下是&lt;s:property /&gt;)...
      猜你喜欢
      • 1970-01-01
      • 2015-02-23
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多