Access Struts 2 variable in JavaScript

时间:2018-10-24 11:24:23

标签: javascript java jsp struts2

I have set a Struts variable in my JSP:

<s:set var="actionName" value="stockCountFind.action" scope="request" />

In the javascript function I access it using

function getAttributeAndGoToAction() {
  var actionName = <s:property value="#actionName"/>;
  alert(actionName);
}

But when I try to call the JS function. It says it isn't defined.

1 个答案:

答案 0 :(得分:0)

尝试使用此:

function getAttributeAndGoToAction()
{
  var actionName = "%{actionName}";
  alert(actionName);
}

只需用 %{ }

包围变量

我以这种方式在.jsp中使用这样的变量:

<s:set var="myVar"><c:out value="${myVar}"/></s:set>
<s:a href="%{myVarRef}" title="%{myVar}" target="_blank">
   ...
</s:a>