A Servlet is a Java class which conforms to the Java Servlet API, a protocol by which a Java class may respond to http requests.
A JSP or java server page is essentially a servlet that allows one to easily mix page logic with markup (html, xml, etc.) and write. JSPs get compiled into servlets which are then executed for http requests
The <%!..%> is used to add declarations in jsp pages
The <% %> code goes into the service method of the compiled JSP (which is a servlet) and is executed there.
More on Declarations and SCriptlets