如何在JavaScript函数中使用Strut标记?

时间:2017-05-31 09:39:57

标签: javascript jsp struts-1

我试图在JavaScript函数中使用struts标记检索值,因为它被调用很多次,并且我不会在需要时对每行进行相应的更改。我想做一次。

我在同一个JSP中使用它:

function myNewWindow(file_type, file_name){
    Window= window.open('MyClassAction_ac.do?metodo=Start&docType='+file_type+'&docName='+file_name,'_blank','width=810,menubar=no,toolbar=no,scrollable=yes,resizable=no');
}

...

<a href="javascript:myNewWindow('<bean:write name="MyClass" property="type"/>','<bean:write name="MyClass" property="name"/>');">
    <img src="<%=path%>img/img1.jpg" width="14" height="14" hspace="0">
</a>

但我需要这样的事情:

function myNewWindow(){
   var file_Type= <%= <bean:write name="MyClass" property="type"/> %>
   var file_name = <%= <bean:write name="MyClass" property="name"/> %>
   Window= window.open('MyClassAction_ac.do?metodo=Start&docType='+file_type+'&docName='+file_name,'_blank','width=810,menubar=no,toolbar=no,scrollable=yes,resizable=no');
}

1 个答案:

答案 0 :(得分:1)

应该有效:

var file_Type= '<bean:write name="instanceofMyClass" property="type"/>'

因此,您需要在其中一个范围内拥有myclass实例:request,session或application

相关问题