aspose file tools*
The moose likes JSP and the fly likes help in jsp declaration and thread safety? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "help in jsp declaration and thread safety?" Watch "help in jsp declaration and thread safety?" New topic
Author

help in jsp declaration and thread safety?

gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

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 ?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Java code in JSPs has been obsolete and discredited for over 10 years now -- why are you still using them?

But to answer the question, yes, creating declarations can make a JSP non-thread-safe. Don't do it.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1027
It fits in exactly.

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)
gurpeet singh
Ranch Hand

Joined: Apr 04, 2012
Posts: 924
    
    1

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: help in jsp declaration and thread safety?