<% ... %>
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…