[英]JSP - what's the difference between “<% … %>” VS “<%= … %>”
While working with JSP
files and servlets , I came across <% … %>
and <%= … %>
. 在使用
JSP
文件和servlet时,我遇到了<% … %>
和<%= … %>
。
What's the difference between both cases ? 这两种情况有什么区别?
Thanks 谢谢
<%= … %>
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文档的链接:
<%= … %>
) : http://java.sun.com/products/jsp/tags/11/syntaxref11.fm4.html <%= … %>
): http : //java.sun.com/products/jsp/tags/11/syntaxref11.fm4.html <% … %>
) : http://java.sun.com/products/jsp/tags/11/syntaxref11.fm5.html <% … %>
): http : //java.sun.com/products/jsp/tags/11/syntaxref11.fm5.html <%= new java.util.Date() %>
is same as 和...一样
<% out.println(new java.util.Date()) %>
There are three types of Scriptlets : Scriptlet有三种类型:
Scriptlet Declarations of the form <%! Scriptlet声明形式<%! code %> that are inserted into the body of the servlet class, outside of any existing methods.
代码%> ,在任何现有方法之外插入到servlet类的主体中。 For ex:
例如:
<%! public int sum(int a, int b) { return a + b; } %>
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 ) %>
的快捷方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.