开发者

What is the difference between <% ... %> and <%! ... %> in jsp

开发者 https://www.devze.com 2023-01-08 15:51 出处:网络
I 开发者_Go百科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

I 开发者_Go百科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


<% ... %> is used to embed some java code within the main service() method of the JSP. It is executed during the rendering of the page.

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

Both approaches are now obsolete, however. JSP EL, JSTL and tag classes are the preferred way of doing the same thing.

0

精彩评论

暂无评论...
验证码 换一张
取 消