how to give action in javascript for get method us

2019-09-17 03:54发布

问题:

Hi i am giving a get request from a jsp page as shown below:

     <c:forEach items="${empNameInfo.empName}"  var="empNameDetail">

         <a href="${contextPath}/empValues?empName=${empNameDetail.eName}&   amp;empNo=${empNameDetail.eNo}">Emp Details </a></c:forEach> 

And its working fine. But now i want to use it in java script so that i can refresh a particluar of other page (i.e. A.jsp having above code but from here i want to refresh the of B.jsp) so how i can give same kind of request in java script so that i can use load method and change a particular content. i mean how i can get ${empNameDetail.eName} ${empNameDetail.eNo} in javascript.

or is their any other way to do the same pls let me know

thanks in advance

回答1:

 <script>
    function myFunction(name,no){
      alert(name+"  "+no);
     }
  </script>

     <c:forEach items="${empNameInfo.empName}"  var="empNameDetail">

     <a href="${contextPath}/empValues?mpName=${empNameDetail.eName}&empNo=${empNameDetail.eNo}" 
      onclick="myFunction('${empNameDetail.eName}','${empNameDetail.eNo}')">

         Emp Details </a>
    </c:forEach>

Or

You can directly use JSTL in your java-script code

   <script>
      <c:forEach items="${empNameInfo.empName}"  var="empNameDetail">
         var name = "<c:out value='${empNameDetail.eName}'/>" ;
         alert(name);

       </c:forEach>
  </script>