2013-03-21 36 views
4

我只是想知道什么是各种功能的执行顺序是由JSPJSP为了

  • scriplets提供
  • 标签库
  • 表达式语言
+0

这可能有帮助。 http://www.onjava.com/pub/a/onjava/2004/06/09/jsf.html – rickz 2013-03-21 15:13:08

+0

也查看生成的servlet java代码。 – 2013-03-21 15:22:25

回答

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容器上,我不这么认为它增加任何价值来理解这一点。

让我知道这是你想知道的全部。