java - JSP各种jsp特性的执行顺序

标签 java jsp

我只是想知道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/

相关文章:

java - Spring Boot YARN如何部署到Hadoop

java - 如何使用 Testng 框架将放心的控制台日志写入可编辑或 txt 文件?

java - 如何从url或路径(目录)描述jtable中rar/zip文件的内容?

java - SEO URL 重写不起作用

java - 如何访问自定义标签中foreach标签中的var变量?

java - 为什么listiterator只为List设计,而Set不是?

java - 为什么 HTML 图像标签在文件协议(protocol)中不起作用?

jsp - 不允许跨源框架 iframe

java - JSP 文件未运行

java - 将数组中的单词放入 HashMap 和 HashSet