Two Laptop Bag*
The moose likes JSP and the fly likes alert function Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "alert function" Watch "alert function" New topic
Author

alert function

chinna kumar
Greenhorn

Joined: Sep 29, 2004
Posts: 18
hi,
i need to pass a variable to alert function,i tried many ways,but i cud not get the result.

this is my code..

<%
String MSISDN=(String) application.getAttribute("Msisdn");
String IMSI=(String) application.getAttribute("Imsi");
String SIM=(String) application.getAttribute("Sim");
%>

<script language="javascript">
function one()
{
alert("value of"+MSISDN+" is"+MSISDN);
}

please advise me on this
Niki Nono
Ranch Hand

Joined: Mar 20, 2005
Posts: 256


in the above code only one of them work.
try out each and you will come across the correct one.
i dont remember the exact one and i dont have a webserver nearby.sorry
try it out and let me know.

[ April 19, 2005: Message edited by: Niki Nono ]
[ April 19, 2005: Message edited by: Niki Nono ]

Life called,so here I am.<br />Cheers<br />Niki.:-)
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
repeat after me, and write it down 10.000 times (Bear will check your homework for spelling errors):
JSP runs on the SERVER, Javascrip runs on the CLIENT. You can NOT call Javascript from JSP nor can you call JSP from Javascript.


42
Sarath Mohan
Ranch Hand

Joined: Mar 17, 2001
Posts: 213
You can NOT call Javascript from JSP nor can you call JSP from Javascript.


Sure???!!!

You are wrong!!! JSP is nothing but a combination Java Code+Java Script+Html Tags.

So we can call java script function in JSP and java script can access java variables declared in jsp.

Cheers


Sarath Mohan
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

JSP is not a combination of those things.
JSP is a server side platform that writes text to an output stream.

Within that stream, you CAN include HTML and Javascript code.
When this code makes it to the browser it will be interpreted and or run.
By the time this happens, the JSP processing will be over and finished and completed and done. If you want to interact with the server again, you will need to POST a new form to the server so the whole process can start again.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I'll try to illustrate that point.
Put this JSP in your server and run it in your browser:


When you click on the button, the alert message will show you the server time and date at the time that the JSP was called.

Let the page sit for a few seconds and click the button again. You will see the same time. You can click on that button all day and see the same time because it's NOT interacting with the server.

If you right click on the page and view it's source, you will see:


This is the output from the JSP.
The new 'Date().toString()' call was made on the server where Javascript can't run. The alert function can only be activated on the browser.
The browser has no idea that the date/time we're looking at is the result of a java.util.Date object. For all it knows it was typed in manually by an HTML designer.


It is always a good idea for a beginning web programmer to get in the habit of viewing the HTML source from the browser. This is what your JSP/Servlet/PHP/Perl/ASP/CF programs are writing.
[ April 21, 2005: Message edited by: Ben Souther ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: alert function
 
Similar Threads
problem in using Ajax calls
java script error help please
How to acess servlet context variables from java class
Does a SIM card contain the phone number
jsp tags inside javascript function