While working with JSP
files and servlets , I came across <% … %>
and <%= … %>
.
在使用JSP文件和servlet时,我遇到了<%...%>和<%= ...%>。
What's the difference between both cases ?
这两种情况有什么区别?
Thanks
谢谢
3 个解决方案
#1
10
<%= … %>
will echo out a variable, where as <% … %>
denotes a script or some code that is executed.
<%= ...%>将回显变量,其中<%...%>表示脚本或某些已执行的代码。
Here are the links to the jsp documentation:
以下是jsp文档的链接:
- Expression (
<%= … %>
) : http://java.sun.com/products/jsp/tags/11/syntaxref11.fm4.html - 表达式(<%= ...%>):http://java.sun.com/products/jsp/tags/11/syntaxref11.fm4.html
- Scriptlet (
<% … %>
) : http://java.sun.com/products/jsp/tags/11/syntaxref11.fm5.html - Scriptlet(<%...%>):http://java.sun.com/products/jsp/tags/11/syntaxref11.fm5.html
#2
8
<%= new java.util.Date() %>
is same as
和...一样
<% out.println(new java.util.Date()) %>
There are three types of Scriptlets :
Scriptlet有三种类型:
- Scriptlet Expressions of the form <%= expression %> that are evaluated and inserted into the output
- Scriptlet表达式<%= expression%>的表达式,它们被计算并插入到输出中
- Scriptlet of the form <% code %> that are inserted into the servlet's service method
- 插入到servlet的服务方法中的<%code%>形式的Scriptlet
-
Scriptlet Declarations of the form <%! code %> that are inserted into the body of the servlet class, outside of any existing methods. For ex:
Scriptlet声明形式<%!代码%>,在任何现有方法之外插入到servlet类的主体中。例如:
<%! public int sum(int a, int b) { return a + b; } %>
#3
5
In case of <% ... %>
you are adding a server side code. And in case of <%= ... %>
you are adding a server side code that automatically prints something. It could be seen as a shortcut for <% out.print( something ) %>
.
如果是<%...%>,则表示您正在添加服务器端代码。并且在<%= ...%>的情况下,您正在添加自动打印内容的服务器端代码。它可以被视为<%out.print(something)%>的快捷方式。
#1
10
<%= … %>
will echo out a variable, where as <% … %>
denotes a script or some code that is executed.
<%= ...%>将回显变量,其中<%...%>表示脚本或某些已执行的代码。
Here are the links to the jsp documentation:
以下是jsp文档的链接:
- Expression (
<%= … %>
) : http://java.sun.com/products/jsp/tags/11/syntaxref11.fm4.html - 表达式(<%= ...%>):http://java.sun.com/products/jsp/tags/11/syntaxref11.fm4.html
- Scriptlet (
<% … %>
) : http://java.sun.com/products/jsp/tags/11/syntaxref11.fm5.html - Scriptlet(<%...%>):http://java.sun.com/products/jsp/tags/11/syntaxref11.fm5.html
#2
8
<%= new java.util.Date() %>
is same as
和...一样
<% out.println(new java.util.Date()) %>
There are three types of Scriptlets :
Scriptlet有三种类型:
- Scriptlet Expressions of the form <%= expression %> that are evaluated and inserted into the output
- Scriptlet表达式<%= expression%>的表达式,它们被计算并插入到输出中
- Scriptlet of the form <% code %> that are inserted into the servlet's service method
- 插入到servlet的服务方法中的<%code%>形式的Scriptlet
-
Scriptlet Declarations of the form <%! code %> that are inserted into the body of the servlet class, outside of any existing methods. For ex:
Scriptlet声明形式<%!代码%>,在任何现有方法之外插入到servlet类的主体中。例如:
<%! public int sum(int a, int b) { return a + b; } %>
#3
5
In case of <% ... %>
you are adding a server side code. And in case of <%= ... %>
you are adding a server side code that automatically prints something. It could be seen as a shortcut for <% out.print( something ) %>
.
如果是<%...%>,则表示您正在添加服务器端代码。并且在<%= ...%>的情况下,您正在添加自动打印内容的服务器端代码。它可以被视为<%out.print(something)%>的快捷方式。