在我的jsp中,我有这样的东西
<%
String isMultipleOfficesExists = (String)request.getAttribute("MultipleOfficesExists");
String isMultipleOfficeSecurity = (String)request.getAttribute("MultipleOfficeSecurityExists");
String envParm = "default";
if("true".equals(isMultipleOfficesExists)){
envParm = "multipleOffice";
}else if("true".equals(isMultipleOfficeSecurity)){
envParm = "multipleOfficeSecurity";
}
%>
在表单底部的“提交”按钮中,我正在调用JavaScript On-click函数。
<input class="white_button_extra_large" type="button" value="<%=goBtn%>" onclick="javascript:selectEnvironment(envParm);">
我的脚本部分是:
function selectEnvironment(envParm)
{
resetToken();
logoutFlag = false;
document.forms[0].action = contextURL+'/login/selectEnvironment?envParam=' +envParm;
document.forms[0].submit();
}
但是我得到
Uncaught ReferenceError: envParam is not defined
我该如何解决?
最佳答案
在JSP中使envParm变量成为全局变量。您的点击事件应如下所示
<input class="white_button_extra_large" type="button" value="<%=goBtn%>" onclick="javascript:selectEnvironment('<%=envParm%>')">
您应该从javascript函数传递值。该参数应具有值。请参阅此链接Passing arguments