What is the difference between <%! %>
and <% %>
in JSP?
Asked
Active
Viewed 9,862 times
17

Steve Chambers
- 37,270
- 24
- 156
- 208

Scicare
- 833
- 5
- 13
- 26
1 Answers
25
<%! %>
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.

no.good.at.coding
- 20,221
- 2
- 60
- 51
-
Hi, does this have anything to do with local variables vs intstance variables? – Scicare Apr 01 '11 at 03:25
-
1@Scicare Sorry, I was still editing the answer - does the update answer your question? – no.good.at.coding Apr 01 '11 at 03:26