Varun
Varun

Reputation: 5061

JSP order of execution of various jsp features

I was just wondering what is the order of execution of various features been provided by jsp

Upvotes: 4

Views: 1883

Answers (1)

Prakash K
Prakash K

Reputation: 11698

I don't think there is any order of execution other than the order in which they appear on the page i.e. the order in which you have written them.

Sample:

<%-- page directive: This would go as the import of the generated class so executes first --%>
<%@ page import="my.foo" %>
<%@ page import="your.foo" %>

<% // this would be second & goes in _jspService method
out.println("This is a sample scriptlet");
%>

<%-- // JSTL Tag: this third (goes in _jspService method) --%>
<c:if test="<%= true %>">
    <%-- // this fourth --%>
    <%= "Sample expression. This will print only after the if is executed ... what! Ofcourse it is obvious :-)" %>
</c:if>

<!-- EL: this fourth (goes in _jspService method) -->
${requestScope}

<% // Scriptlet: this fifth (goes in _jspService method)
if (true) {
%>
This should be printed after the zero of expression language :-)
<!-- (goes in _jspService method) -->
<%
}
%>

// this sixth (goes in _jspService method)
<div>
Just some HTML element to make is more interesting.
I wonder I am even answering this question !!
Is it for points ... ssshhhhhh ...
</div>

<%! // Declaration: executes before everything (goes as an instance variable) may be placed before or after the _jspService method depends on the container
boolean declareME = true;
%>

But if you are asking about in which order the elements of the JSP would be compiled in a java class then it depends on the servlet-container and I don't think so it adds any value to understand that.

Let me know if this is all you were wondering about.

Upvotes: 1

Related Questions