1. append the value of your javascript variable to your URL, for example:
<script>
var jsvar = "whatver";
window.location.href += "?jsvar=" + jsvar;
</script>then use request.getParameter("jsvar") inside your JSP page to retrieve the value2. add a hidden input control in a form, before you submit the form, set the value of that hidden control to the value of your javascript variable:<form name="frm" onsubmit="return checkInput()">
<input type="hidden" name="jsvar">
<input type="submit">
</form>
<script>
var jsvar = "whatever";function checkInput()
{
document.frm.jsvar.value = jsvar;
return true;
}
</script>then use request.getParameter("jsvar") inside your JSP page to retrieve the value
<script>
var jsvar = "whatver";
window.location.href += "?jsvar=" + jsvar;
</script>then use request.getParameter("jsvar") inside your JSP page to retrieve the value2. add a hidden input control in a form, before you submit the form, set the value of that hidden control to the value of your javascript variable:<form name="frm" onsubmit="return checkInput()">
<input type="hidden" name="jsvar">
<input type="submit">
</form>
<script>
var jsvar = "whatever";function checkInput()
{
document.frm.jsvar.value = jsvar;
return true;
}
</script>then use request.getParameter("jsvar") inside your JSP page to retrieve the value
<head>
<title>无标题文档</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head><body bgcolor="#FFFFFF" text="#000000">
<form name="frm" onsubmit="return checkInput()">
<input type="text" name="jsvar" value="abcd">
<input type="submit">
</form>
<script>
var jsvar = "whatever";function checkInput()
{
document.frm.jsvar.value = jsvar;
return true;
}
checkInput()</script>
<%
String tempstr;
tempstr = request.getParameter("jsvar");
out.println(tempstr);
%>
</body>
</html>
<script>
function testvar()
{
var jsvar = "whatver";
window.location.href += "?jsvar=" + jsvar;
}
</script>
<a href="#" onclick="testvar()">click here</a>2. try click on the submit button again, you should see "whatever" displayed3. what kind of web server are you using?