<%...%>之间的区别是什么?和<%! ......%>在jsp中 [英] What is the difference between <% ... %> and <%! ... %> in jsp

查看:456
本文介绍了<%...%>之间的区别是什么?和<%! ......%>在jsp中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为标题中提到的两个标签的页面添加更多功能。我注意到我在<%...%> 中声明的变量不能用于<%! ...%> ,反之亦然。两者之间的区别是什么?如何声明可以在两个标签中使用的变量

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()方法。通常,这用于定义将在<%...%> 块中调用的实用程序方法。

<%! ... %> 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.

这篇关于&lt;%...%&gt;之间的区别是什么?和&lt;%! ......%&gt;在jsp中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆