JSP执行各种jsp功能的顺序

时间:2013-03-21 15:06:15

标签: java jsp

我只是想知道jsp

提供的各种功能的执行顺序是什么
  • scriplets
  • 标记库
  • 表达语言

1 个答案:

答案 0 :(得分:1)

除了它们在页面上出现的顺序,即你编写它们的顺序之外,我认为没有任何执行顺序。

样品:

<%-- 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;
%>

但是如果你问的是JSP的元素将以哪种顺序在java类中编译,那么它依赖于servlet-container,我不认为它会增加任何值来理解它。

请告诉我这是否是你想知道的。