How to call function of JavaScript from servlet

javascript, servlets

Solution

It is not possible to call a java script function from a servlet. Rather, you can print javascript code using

`response.getOutputStream().println("[javascript code]");`

into the browser and then the javascript function will be executed in the browser.

Problem

I am new to web development. I have an external JavaScript file which has a function to show a prompt with error details. I need to pass the error message to the function. I have written contoller in servlet. How to call the function of that JavaScript file from my servlet.

Original source