My jsp does not seem to run in the order I would expect ..

<%@ include file="/Site-English/Common/progressWindowInsert.html" %>
	<script language="javascript" type="text/javascript">
	    alert("do this");
System.out.println("print out this line  !!");   %>

The System.out.println commmand is written before I respond to the alert. Any explanations would be much appreciated.

Edited by __avd: Added [code] tags. For easy readability, always wrap programming code within posts in [code] (code blocks).

7 Years
Discussion Span
Last Post by stephen84s

The System.out.println is run on the server side when the Web Server detects that someone has requested for your JSP page.
Following is in brief the lifecycle of a JSP page:-

When a request is mapped to a JSP page, it is handled by a special servlet that first checks whether the JSP page's servlet is older than the JSP page. If it is, it translates the JSP page into a servlet class and compiles the class. During development, one of the advantages of JSP pages over servlets is that the build process is performed automatically.

The servlet generates the HTML code (inclusive of your Javascript) which should be displayed and sends it to your browser. The browser is the one that actually runs your Javascript code which shows the alert box, hence the message is printed on the console even before you respond to the alert box.
In fact a simple way to confirm this is by viewing the source of your webpage from the browser (Ctrl + U in firefox), you will notice that none of your java code is present, only the generated HTML and client side Javascript.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.