<% ... %> 和有什么不一样?和 <%!...%>在jsp中 [英] What is the difference between <% ... %> and <%! ... %> in jsp

查看:16
本文介绍了<% ... %> 和有什么不一样?和 <%!...%>在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

推荐答案

<% ... %> 用于在主service()<中嵌入一些java代码/code> JSP 的方法.它在页面渲染期间执行.

<% ... %> 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;%!...%>在jsp中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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