3

What will execute first body elements or head elements...

  1. Head
  2. Body
  3. scriplet
avi
  • 21
  • 3

3 Answers3

2

If I get what you're asking, each element in the JSP file is processed in the same order as it appears from top to bottom of your code.

Pablo Fradua
  • 369
  • 1
  • 4
  • 16
1

Obviously, the scriptlets embedded in your JSP are executed to create the HTML. The scriptlets, and other server-side-executable stuff in the JSP is executed top to bottom.

(The JSP is not aware of the HTML elements it is generating. It processes the JSP / JSTL syntax embedded in the JSP file, and treats the rest as text to be copied into the document sent to the browser. That's why you can, in theory, use JSPs to generate any text-based document.)

The generated HTML is then sent to the browser ... which is where any client-side javascript embedded in the HTML will be executed.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
  • Thanks for valuable suggestion. – avi Jan 23 '17 at 12:09
  • I like how this start with a bit of humour _Obviously, the scriptlets embedded in your JSP are executed to create the HTML_ when 50% of JSP questions doesn't get that difference ;) @avi, don't forget to accept the answer where you found what you where looking for. – AxelH Jan 23 '17 at 12:35
1

JSPs are servlets that add syntactic sugar to facilitate developers. All JSP compile to servlet first and at runtime class files of that compiled JSP.

Following diagram explains the JSP compilation/execution in detail:

enter image description here

HTML/JS are executed on browser(client side) once server side script finalize the response as HTML.

Rex5
  • 771
  • 9
  • 23
Zeeshan Bilal
  • 1,147
  • 1
  • 8
  • 22