【问题标题】:Pass Javascript variable to servlet doGet method将 Javascript 变量传递给 servlet doGet 方法
【发布时间】:2014-07-21 18:00:52
【问题描述】:

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

我的问题是,如何将计算机名(函数的结果)传递给 servlet doGet() 方法?

目前我调用servlet的代码(sn-p)如下:

    <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>

【问题讨论】:

  • 你如何调用 servlet?只需将其作为查询参数传递。 setletPath?computerName=xyz
  • 我正在使用 response.sendRedirect(redirectURL);
  • 所以你在按钮/超链接点击时调用它吗?
  • @GoAlves 这取决于你在哪里使用它。目前,正如它所写的那样,很难告诉你它。请详细说明问题。
  • 嗨!我用代码 sn-p 编辑了我的问题,以更好地说明该主题。谢谢!

标签: java javascript jsp servlets web


【解决方案1】:

让客户端重定向。

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

但在我的机器上不起作用。我在 Linux 上,所以没有... ActiveX。

【讨论】:

    猜你喜欢
    • 2012-10-24
    • 2015-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-18
    • 2014-04-15
    • 1970-01-01
    • 2013-03-22
    相关资源
    最近更新 更多