将Javascript变量传递给servlet doGet方法

时间:2014-07-21 18:00:53

标签: java javascript jsp servlets web

我有一个javascript函数来检索这里的用户工作站。 How can I read the client's machine/computer name from the browser?

我的问题是,如何将computername(函数的结果)传递给servlets的doGet()方法?

目前我调用servlet的代码(代码段)如下:

    <html>
    <head> .... <script> load my javascript file here </script></head>
    <%
      if(session.getAttribute("Login") == null){
         //I want to pass the computer name here
         response.sendRedirect("../LOGME");
      } else {
        //draw page body
      } %>
     </html>

1 个答案:

答案 0 :(得分:0)

让客户重定向。

<%
  if(session.getAttribute("Login") == null){ %>
     <script>
         location.href = "../LOGME?name=" + yourValue;
     </script>
 <% return; // you should check the return ...
  } else {
    //draw page body
  } %>

虽然不能在我的机器上工作。我在Linux上,所以没有... ActiveX。

相关问题