File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet" Watch "Servlet" New topic


Soman Singh
Ranch Hand

Joined: Sep 02, 2003
Posts: 37
Hi Folks,
I am new to Servlets. Can we declare a Sting variable in Servlet?
If no then Why?
Thanks in advance,
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
Are you referring to having member variables in your servlet? If so then yes, you may declare it. It is generally recommended that your servlet not have member variables because they are not thread safe.

Matthew Phillips
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
Just to amplify what Matthew said - you should not use member variables for anything that is user specific. Remember that more than one request can be processed "at the same time" in a servlet object. Its ok to use a member variable or a static variable for something that does not relate to a specific user.
I agree. Here's the link:
subject: Servlet
It's not a secret anymore!