I want to compare a javascript variable with a jsp variable. How can I do this?
function verify_details()
{
var resourceId=document.getElementById("res").value;'
<%! String rId;%>
<%
for(int i=0;i<l.size();i++)
{
rId=l.get(i).toString开发者_Python百科();
System.out.println("Elements Are:"+rid);
%>
if(resourceId==rId)
alert("Alloted");
else
alert("Not Alloted");
<%}%>
}
You shouldn't be doing this in the first place. See this.
If you really want to, make a new JSP with this code in it, pass the variable you want to compare as a parameter (call that page with AJAX) and get the result.
But, that's overly complicated and this situation should really never occur in code that is well structured.
Use some control like 'hidden' or any other. Its value will be accessible in both javascript
and jsp
.
精彩评论