简体   繁体   English

在JSTL中获取从Javascript到Sql查询的变量

[英]Get a variable from Javascript to Sql query in JSTL

I developed in Java EE and I want to take a javascript variable (which I obtained from another jsp page mother) I want to use it in a query sql server in the same page pop1.jsp, here is my code: 我用Java EE开发,我想获取一个javascript变量(该变量是从另一个jsp页面的母亲那里获得的),我想在同一页面pop1.jsp的查询sql服务器中使用它,这是我的代码:

<html>
<head>
<script type="text/javascript">
var valeur= opener.document.getElementById("formulaireFournisseur").idfour.value;
function affectation(){
    var valeur;
      valeur= opener.document.getElementById("formulaireFournisseur").idfour.value;
      document.write(valeur);
       document.getElementById("form").champ.value=opener.document.getElementById("formulaireFournisseur").idfour.value;

}
</script>
</head>
<body>
<sql:query var="result" dataSource="Achat"> 

  Select * FROM dbo.Fournisseur WHERE nom LIKE ?

   </sql:query>       
  <sql:param> '%$valeur%' </sql:param> 
<table border="1">

       <!-- column headers -->
       <tr>
           <c:forEach var="columnName" items="${result.columnNames}">
               <th><c:out value="${columnName}"/></th>
               </c:forEach>
       </tr>
       <!-- column data -->

       <c:forEach var="row" items="${result.rowsByIndex}">
           <tr id="${result.rowsByIndex}" ondblclick="SelectLigne(this);window.close() ">
               <c:forEach var="column" items="${row}">
                   <td><c:out value="${column}"/></td>
               </c:forEach>
           </tr>
       </c:forEach>
   </table>       
</body>
</html>

I want to recover $ value in the code of the SQL query and execute my sql mequete correctly. 我想在SQL查询的代码中恢复$值并正确执行我的sql mequete。 please help me 请帮我

  1. The sql-code is executed on the server. sql代码在服务器上执行。
  2. After that, the page is generated and sent to the client requesting it. 之后,将生成该页面并将其发送给请求它的客户端。
  3. The client browser will then process the javascript. 然后,客户端浏览器将处理javascript。

Your solution will not work. 您的解决方案将不起作用。 It tries to work in the opposite order. 它尝试以相反的顺序工作。 Also, as sql and javascript are executed on different machines (server and client) you will have to rewrite this. 另外,由于sql和javascript是在不同的机器(服务器和客户端)上执行的,因此您必须重写它。

You probably need to construct a form with the valeur value to submit to the server. 您可能需要构造一个具有valeur值的表单,以提交给服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM