i am reading Head first servlet and jsp book. i have learned that in a servlet instance variables are not thread safe and a well written servlet wont have any instance variables. in the chapter of jsp the book says that a jsp becomes a servlet. also using jsp declarations <%! > we can declare instance varialbes, static variables etc. so how does this thing fits into the earlier part that a well written servlet does not or should not have instance variables ? or are instance variables declared using jsp declarations thread-safe ?
Using <%! scriptlet declaration tag %> you can declare an instance variable for your jsp/servlet.
It is exactly the same deal as declaring an instance variable in a servlet: they are not thread safe, and are thus their usage is discouraged.
In fact, scriptlets in general on a JSP page are discouraged. Instead you should be using EL and custom tag libraries (like JSTL)
Thanks Bear and Stefan. and yes i know that scripting elements in jsp are not good and we should be using EL and JSTL. im preparing for ocewcd 6 certification and right now just at the start of jsp chapter whereby author is telling me various scripting elements and where they land in the container generated servltet.