Java and JavaScript are two entirely distinct languages which runs each on its own environment. Java/JSP runs at the webserver machine, produces template text including HTML/CSS/JS and sends it over network to the client side as a HTTP response. Once arrived at the client machine, the webbrowser starts to display HTML, apply CSS and interpret/execute JS. If Java/JSP has done its job well, you should not see any line of Java/JSP code in the obtained HTML source (rightclick page > View Source).
The only way to let Java/JSP do something with JavaScript is to generate/print it accordingly that it get interpreted/executed in the client side the way you want. The only way to let JavaScript do something with Java/JSP code is to let it fire a HTTP request to an URL on which a JSP file or a Java Servlet listens and then exectues accordingly. You can fire a HTTP request with form.submit()
, window.location
and new XMLHttpRequest()
(which is the base idea of Ajax).
In your particular case, you can just use window.location
:
function msg() {
alert('List of Users');
window.location = 'Users.jsp';
}
or if this button is part of a <form>
, then just specify it in the form action:
<form action="Users.jsp" onclick="msg()">
<input type="submit">
</form>
with
function msg() {
alert('List of Users');
}
To learn more about the wall between Java/JSP and JavaScript, you may find this article useful. As to learning Web Development in general, you may find this answer useful and for Java Web Development this answer.