在我的struts2应用程序中,我有一个JavaScript函数来执行取消操作。此方法在标题中,仅对我的返回URL进行window.location。由于我们从struts 2.3.8版本的2.0.11版本进行了迁移,因此它不再起作用。当我查看生成的HTML代码时,我们看到由于URL为空,因此无法解释标记s:property。我看不到什么不起作用。

在我的IDE中:

function cancel() {
        if (!isModified || (isModified && askConfirmCancel())) {
            window.location.replace('<s:property value="#urlBack"/>');
        }
    }


Firebug的结果:

function cancel() {
        if (!isModified || (isModified && askConfirmCancel())) {
            window.location.replace('');
        }
    }


在JSP文件中:

<tr>
    <td height="6%"align="center">
      <s:submit cssClass="button" key="common.initDelegate.label" align="center" theme="simple"/>
      <s:url id="urlBack" action="myAction" includeParams="none" escapeAmp="false">
        <s:param name="period.periodId" value="%{period.periodId}"></s:param>
      </s:url>
      <input type="button" onclick="javascript:cancel()" value="<s:text name="common.button.cancel"/>"/>
    </td>
  </tr>

最佳答案

<s:property value="#urlBack"/>-在urlBack之前是否需要“#”。我们需要的只是使用urlBack方法的操作类中的public String getUrlBack()属性。并且该变量应在Action返回成功/结果之前进行初始化。

关于java - 如何在JavaScript函数中使用s:property,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20197138/

10-10 16:27