0

I have a jsp file which has a submit button. On clicking this the call goes out to a different angular app. I want to log which user is clicking the button. For this I am thinking of calling a javascript function. Inside the javascript function callJSFunction() I want to pass the username of the user and call a java function. Inside the java function I need to store the user details in th db. My question is how can I call a java method (for logging) from the javascript. I am sure this a common use case for logging information in jsp. I am not sure how to achieve this? Any help is greatly appreciated.

<A class="gridlink1" id="portal"
    title="Go to portal for <%= StringEscapeUtils.escapeHtml(resultBn.getName()) %>"
HREF="<%= resultBn.getLink() %>" onclick = "callJSFunction()"> <%=resultBn.getID()%>
</A>

function callJSFunction(){
    alert("hello"); //palceholder
}
imba22
  • 651
  • 1
  • 13
  • 25
  • When you send a request to a JSP it sends HTML back to the client in the response. When the user clicks a button, you could use Angular's HttpClient to communicate with your server. – rickz Feb 23 '22 at 18:46
  • @rickz thanks for taking time to answer this. Unfortunately this is a basic old school jsp java app and I cannot invoke using angular. Is there any other way you can think of to call java method from anchor tag click event – imba22 Feb 23 '22 at 20:18
  • Angular uses XMLHttpRequest . You could use that directly or you could use fetch(). – rickz Feb 23 '22 at 20:45
  • @TimMoore it does not, but thank you for taking time and trying. – imba22 Feb 24 '22 at 21:02

0 Answers0