Executing some JavaScript feature explicitly in a Java application is impossible. In fact, this is not restricted only to Java, but to any Server-Side language with the exception of Node.JS , which does not explicitly work with front-end.
To solve your problem, you can use AJAX . A very simple way to solve this is with a solution that you yourself proposed in an earlier comment: send data via an HTTP request in JSON format.
Conceptually, what you need to do is pretty simple: serialize the content you want to send to JavaScript through a < a href="http://www.json.org/java/"> Java method and then, there on the front end, in JavaScript code, you can do something like this using jQuery library :
$.ajax({
url: 'localhost/user',
success: function (response) {
console.log(response);
}
});
Being url
the address you make available your data in JSON - through your Java application - and the success
method to work with the return if the request is made, suggestively, successfully.
The response
parameter of the success
method is the data sent by your Java application. From there, you can work as you see fit.
In this link I take a pretty similar approach that can be useful.