Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Servlets and the fly likes ConstantsUtil class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "ConstantsUtil class" Watch "ConstantsUtil class" New topic
Author

ConstantsUtil class

prasad naga
Greenhorn

Joined: Jan 05, 2006
Posts: 10
Hi
can any body explain me about ConstantsUtil class and why do we initialize it in init() of servlet.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
Welcome to JavaRanch.

Is this the class you're talking about? It's the only class of that name Google knows about. I think that would more properly be a question to whoever wrote the code you're looking at, as it's not a commonly used class.


Ping & DNS - my free Android networking tools app
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Never heard of it
Where did you see it ? In a book ?


[My Blog]
All roads lead to JavaRanch
prasad naga
Greenhorn

Joined: Jan 05, 2006
Posts: 10
no i haven't viewed in any book, i just saw in my project which consists of
ConstantsUtil class that imports java.lang.reflect.Field and declares a constants like SERVLET_SUFFIX,SERVLET_METHOD,ACTION,ITEM,etc..
Here the ACTION AND ITEM were the variables that are to be declared.(i.e which were avilable in the jsp) and apart from this which consists of a method that returns Hashmap.
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by prasad naga:
no i haven't viewed in any book, i just saw in my project which consists of
ConstantsUtil class that imports java.lang.reflect.Field and declares a constants like SERVLET_SUFFIX,SERVLET_METHOD,ACTION,ITEM,etc..
Here the ACTION AND ITEM were the variables that are to be declared.(i.e which were avilable in the jsp) and apart from this which consists of a method that returns Hashmap.


Sounds like implementing Command Pattern using HashMap.
Where is the problem?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by prasad naga:
can any body explain me about ConstantsUtil class and why do we initialize it in init() of servlet.


You people are initializing that in your init() because your servlet is most probably working as a FrontController. The servlet need to check the command/action (Key in a HashMap object) to get the corresponding handler object in order to fulfill the request. So, the HashMap must be initialized before start serving the requests.
 
Don't get me started about those stupid light bulbs.
 
subject: ConstantsUtil class