4

我只是想知道jsp提供的各种功能的执行顺序是什么

  • 脚本
  • 标签库
  • 表达语言
4

1 回答 1

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,我认为它不会增加任何理解这一点的价值。

让我知道这是否是您想知道的全部。

于 2013-03-21T16:15:31.563 回答