Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

multiple JSPs: order of execution  RSS feed

 
Paul Fenerty
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have a JSP (main.jsp) with a javascript file referenced within the HTML HEAD tag. Since the javascript needs to populate certain arrays from the session bean, it is itself a JSP (js.jsp). This array population code exists outside of any function calls.

The bean caches certain properties that must be loaded from the database, such that multiple calls only go out to the database once. Both main.jsp and js.jsp need a certain property (the same one). For testing purposes, I have added alert boxes to both code blocks.

All of this works fine, but this sequence seems surprising:

1) js.jsp alert box announces it accessed the bean property second.
2) main.jsp alert box announces it accessed the bean property first.

I expected js.jsp to alert first, running from HEAD, but i didn't expect main.jsp to get to the bean first, for the same reason.

Is the order of execution for various JSPs that contribute to the final markup specified ... e.g., embedded JSPs always run after containing JSPs?

What if there are also include-directive JSPs ... is order of execution specified simply to follow the (linear) order that embedded JSPs are encountered in the containing JSP, regardless of any enclosing semantic elements, but only after the containing JSP is run?

Thanks!
 
Duc Vo
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It should be main.jsp first because js.jsp acts as a script file, it will be loaded by the browser as directed in the main.jsp (i.e. after the server process main.jsp).

The sequences are:
(1) Browser requests main.jsp
(2) Server processes main.jsp, send to browser
(3) Browser parses main.jsp for any related resources (i.e. script and/or css and/or image files)
(4) Browser requests to load related resource files
(5) Server processes related resources (i.e. js.jsp) and send to browser

Hope it is clear to you now.
 
Paul Fenerty
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
of course! run only at request time ... thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!