What is the difference between <%! %>
and <% %>
in JSP?
Difference between JSP Scriptlet tag and Declaration tagThe jsp scriptlet tag can only declare variables not methods. The jsp declaration tag can declare variables as well as methods.
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.
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.
The main difference between JSP and HTML is that JSP is a technology to create dynamic web applications while HTML is a standard markup language to create the structure of web pages. In brief, JSP file is an HTML file with Java code.
<%! %>
are JSP Declaration tags while <% %>
are JSP Scriptlet tags.
Any code you put in scriptlets gets put in the JSPs _jspService()
method when it's compiled (the analogue of a Servlet's doGet
, doPost
,... methods). This is what you'd usually write your Java code in.
But what if you want to declare new methods in your JSP class or declare instance variables? That's when you'd use the declaration tags. Any thing you put in there gets put into the JSP, outside of the _jspService()
method.
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