问题描述
我正在为标题中提到的两个标签的页面添加更多功能。我注意到我在<%...%>
中声明的变量不能用于<%! ...%>
,反之亦然。两者之间的区别是什么?如何声明可以在两个标签中使用的变量
I am adding some more functionality to a page that has the two tags mentioned in the title. I noticed that the variable I declare in <% ... %>
cannot be used in <%! ... %>
and vice versa. What is the difference between the two and how can I declare variables that could be used in the two tags
推荐答案
<%...%>
用于在JSP的主 service()
方法中嵌入一些java代码。它在呈现页面期间执行。
<% ... %>
is used to embed some java code within the main service()
method of the JSP. It is executed during the rendering of the page.
<%! ...%>
用于定义页面流的外部,因此在主 service()$之外c $ c>方法。通常,这用于定义将在
<%...%>
块中调用的实用程序方法。
<%! ... %>
is used to define code outside of the flow of the page, and therefore outside the main service()
method. Typically, this was used to define utility methods that would be called from within a <% ... %>
block.
然而,这两种方法都已过时。 JSP EL,JSTL和标记类是做同样事情的首选方式。
Both approaches are now obsolete, however. JSP EL, JSTL and tag classes are the preferred way of doing the same thing.
这篇关于<%...%>之间的区别是什么?和<%! ......%>在jsp中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!