0

I am trying to pass java script value to java method in JSP.

But it is NOT working. Can anybody please tell how I can achieve this or is there any alternative solution for this ?

<script type="text/javascript">
   function myjsfunc(){
       var myef = $(this).data('myrefval');
       var myurl ="http://example.com/mycontext?param="+myef;
       var myurlData = '<%=callJavaMethod(myurl)%>'; // this is NOT working.It is Not understanding myurl variable
       processData(myurlData);
    }
    function processData(finaldata){
    }
<script>

<%!
public String callJavaMethod(String param){
  System.out.println(param); // process here param and return string data
}
%>
  • possible duplicate of [call a jsp method from javascript](http://stackoverflow.com/questions/11401674/call-a-jsp-method-from-javascript) – Marko Gresak Jun 21 '15 at 03:07
  • Thanks Marko.But calling jsp using ajax will give entire jsp content not the API response. To get only API response what might be the way ? – Bhushan sharma Jun 21 '15 at 03:35
  • You can't just call Java (JSP) method from javascript, it doesn't work as simple as that. You will have to design the API response to be what you're expecting, so make it return a JSON string. – Marko Gresak Jun 21 '15 at 03:37

0 Answers0