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

解决方案 »

  1.   

    如果用第一种方法那将会是一个死循环,用第二种方法得出的是空值,代码如下:<html>
    <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>
      

  2.   

    1. of course you will get a loop, what I mean is something like this:<%=request.getParameter("jsvar")%>
    <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?
      

  3.   

    我说的是同一页面里如何取而不是点个按钮把这个变量搞过去,不过我现在不这样做了,我觉得这样的编程思路是错误的。我用的是jswdk,打算转到websphere,要是我的内存够多我早就无为老兄能谈谈b/s开发的架构和思想吗?如何设计才能使insert/delete/save/edit/show list/show form/security/exception这样的流程尽量通用呢?如何能把一个任务细化呢?我想这应该是b/s开发中最重要的吧,用c/s我能解决的很好[email protected]