"Ganesh N", The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements. Thanks.
Hi Ganesh, JSP code can be mixed with Javascript code but it is important to consider when each type is run: Javascript is run as part of the web page dynamically while the user is displaying the page. JSP is compiled and run before the page is displayed to the user and determines the content of the page. So you could have the following Javascript code with JSP in it which displays an alert message to the user with the compiled message string 'I was compiled earlier' produced during JSP compilation: // extract from a jsp page <% String messageText = "I was compiled earlier"; %> //jsp <script> //javascript alert("The message is <%= messageText %>"); // </script> // While this script could be triggered at any time during the page display, the 'messageText' string will only change if the page is redisplayed (ie recompiled). You could also use JSP functions to decide what Javascript will be published in the page, eg: <% boolean boolSayHello = true; %> <% if (boolSayHello == true) { %> //jsp <script> alert("Hello"); </script> //javascript <% } else { %> //jsp <script> alert("Goodbye!"); </script> //javascript <% } %> //jsp In this example the boolean is set to true so the alert message 'Hello' would be displayed. The script would run when the page is displayed but the jsp would be run when during page compilation before you see it. Hope this answers your question. Regards, Richard
Post by:autobot
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
a bit of art, as a gift, the permaculture playing cards