Paritosh Das
How to pass javascript variable in Scriplet of JSP?
1 Answer(s)      4 years and 4 months ago
Posted in : JavaScript Questions

How can I assign the value of a javascript variable to a variable declared in jsp scriplet? Is it possible?

Advertisement
View Answers

April 26, 2011 at 11:23 AM


We are providing you two ways:

1)a.jsp:

<html>
<script language="javascript" type="text/javascript">
function call(){
var name = "roseindia";
window.location.replace("a.jsp?name="+name);
}
</script>
<input type="button" value="Get" onclick='call()'>
<%
String name=request.getParameter("name");
if(name!=null){
out.println(name);
}
%>
</html>

2)b.jsp:

<script>
var v="Roseindia";
</script>
<% String st="<script>document.writeln(v)</script>";
out.println("value="+st); %>









Related Tutorials/Questions & Answers:
Advertisements