Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between <%! %> and <% %> in JSP?

Tags:

jsp

scriptlet

What is the difference between <%! %> and <% %> in JSP?

like image 980
Scicare Avatar asked Apr 01 '11 03:04

Scicare


People also ask

What is the difference between scriptlet <% %> and Decleration <%! %>?

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?

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.

What is the difference between JSP and tag file?

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.

What is the difference between HTML page in JSP page?

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.


1 Answers

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

like image 185
no.good.at.coding Avatar answered Oct 20 '22 12:10

no.good.at.coding