• Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling Javascript funtion from Java code  RSS feed

 
Swapnil Gaurshettiwar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Happpy New Year.

I am new to this JSTL and JSP.
I have a JSP page on which I have a Java code(a method) in which I want to place an alert.For that I have written a Javascript function(for alert) and trying to call it from Java code,but I cant ...
can anyone suggest me any other option to call an alert from JAVA code.

Regards,
Swapnil G.
 
Kudret Serin
Ranch Hand
Posts: 167
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try following?
 
Swapnil Gaurshettiwar
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<%// Your JSP code here
String alertText = "This is a text for alert!";
%>
<script type="text/javascript">
alert('<%= alertText%>');
</script>
<%// Your JSP code can continue.. %>

If I go with this way for the line alert('<%= alertText%>'); it says "No variable or field found at this location.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66152
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't. Please read this article to understand why.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!