• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getInitParameter method in ServletContext and ServletConfig

 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is there a getInitParameter method in ServletContext and ServletConfig.Cant we get it using getAttribute methods in both?
 
PRavi kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,

The getInitAttribute method in servlet ZConfig to get the servlet Init parameters defined in DD.

Example
<servlet>
<servlet-name>abc</servlet-name>
<servlet-class>coom.abc.y</servlet-class>
<init-param>
<param-name>xyz</param-name>
<param-value>abc</parama-value>
</init-param>
</servlet>

The getInitparameter method the Servlet Context will be used for get the initial parameters of servlet Context.
 
Joe Harry
Ranch Hand
Posts: 10110
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that the init parameters are available to your servlet/jsp when those servlet/jsp's are being initialized...i.e. when their init() methods runs. On the other hand your attributes are available only when the service method runs. So if you want any information along with your servlet initialization, then initParameters to the rescue...Hope you understood...
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ServletContext's getInitParameter is just here for convenience. It simply calls ServletConfig's. Attributes is a different story. You set attributes in the context, so it should not be in ServletConfig. Init parameters are set in web.xml, so they can be considered both as being part of the config and the context. (that's how I see it )
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The getInitAttribute method in servlet ZConfig

There's no getInitAttribute
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is there a getInitParameter method in ServletContext and ServletConfig.

Because they return different init parameters. The context configuration (of which there is a single one for a web app) is not the same thing as the servlet configuration (of which there is one for each servlet).

Cant we get it using getAttribute methods in both?

Init parameters are not attributes, and thus can't be accessed via getAttribute.
[ June 25, 2007: Message edited by: Ulf Dittmer ]
 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok..so cant I use getattribute in the init method???
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posted by Renu Radhika
so cant I use getattribute in the init method?

Again: init parameters are not attributes.

Posted by Satou kurinosuke
ServletContext's getInitParameter is just here for convenience. It simply calls ServletConfig's.

This is not correct; see my post above.

Posted by Jothi Shankar Kumar Sankararaj
Remember that the init parameters are available to your servlet/jsp when those servlet/jsp's are being initialized...i.e. when their init() methods runs.

Yes, but they can also be accessed later, so that doesn't differentiate them from attributes.
[ June 25, 2007: Message edited by: Ulf Dittmer ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not correct; see my post above.

Dooohhh, that's right. I got mixed up with GenericServlet#getInitParameter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic