try,
Main Topics
Browse All TopicsHi all experts!
Consider following code...
I want a javascript alert() should be displayed on client side when my application executes perticular jsp method.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The answer given is correct but it did not solve my problem perfectly. In my later comments I have asked what to do if I want to call JavaScript alert() from a JSP method. i.e. within <%! ---- %>. Is this possible?
The answer is no. What happens when a JSP function is called, the code within JSP function is executed on server itself. We know JavaScript is client side scripting language. Thus trying to run Client side script from Server is meaningless.
But I have done what I was trying to do. I was trying to display a JavaScript alert to display a message on client browser. I have simply made the return type of the JSP function to String. (I think you have now understood) I have used the String retrieved by JSP function outside the declaration tag <%! %>.
<%!
public String message()
{
if(cond1)
{
return "Cond1";
}
else
{
return "cond2";
}
}
%>
<html>
<head>
</head>
<body onload="alert('<%=message(
</body>
</html>
However, I am still searching for some efficient ways to do this in more effective manner. May be I need to use AJAX. Anyways this is enough for now. Thank you all for your expert comments.
Business Accounts
Answer for Membership
by: objectsPosted on 2009-07-27 at 03:22:00ID: 24950058
you can't. jsp is executed on the server, whereas the javascript is executed on the client