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
<%@ is the directive attribute. You may include a page or may declare a tag-library using <%@ More on it here.
What is the difference between <jsp:include page = ? > and <%@ include file = ? > <%@ include file=”filename” %> is the JSP include directive. At JSP page translation time, the content of the file given in the include directive is 'pasted' as it is, in the place where the JSP include directive is used.
JSP is slower than Servlets, as the first step in the JSP lifecycle is the conversion of JSP to Java code and then the compilation of the code. Servlets are Java-based codes. JSP are HTML-based codes. Servlets are harder to code, as here, the HTML codes are written in Java.
A tag file is a source file that contains a fragment of JSP code that is reusable as a custom tag. Tag files allow you to create custom tags using JSP syntax. Just as a JSP page gets translated into a servlet class and then compiled, a tag file gets translated into a tag handler and then compiled.
<% ... %>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With