我只是想知道jsp提供的各种功能的执行顺序是什么
- 脚本
- 标签库
- 表达语言
最佳答案
除了它们在页面上出现的顺序,即您编写它们的顺序,我认为没有任何执行顺序。
示例:
<%-- 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 容器,我认为它不会增加任何理解这一点的值(value)。
如果您只是想知道这些,请告诉我。
关于java - JSP各种jsp特性的执行顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15551191/