You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Nishant <ni...@cybage.com> on 2004/11/24 14:02:43 UTC
how do i get context-param
hi
can anyone tell me how can i get context-param parameter in my servlet .
thanks in advance
Regards
Nishant Patil
Software Engineer
Cybage Softwares Pvt. Ltd. (A CMM Level 3 Company)
West Avenue, Kalyaninagar
Pune - 411006
Ph. +91-20-4044700/4041700 Extn 355
nishantp@cybage.com
www.cybage.com
"There is difference between knowing the Path and walking on the Path"
Re: [OT] how do i get context-param
Posted by Struts User <st...@gmail.com>.
I had the same feeling that servlet spec. should be more specific when
I just started working with J2EE:)
But, my experience tells me that a specification tells you "What" you
need to have in a servlet container and not "How" to implement a
servlet container.
If I want to learn servlet programming, I usually pick up Jason Hunter's book.
Lee
On Wed, 24 Nov 2004 14:57:14 -0500, Erik Weber <er...@mindspring.com> wrote:
> Good point. I guess the J2EE tutorial would be the place for stuff like
> that (I was trying to only speak of "official" documentation).
>
> Erik
>
>
>
>
> Craig McClanahan wrote:
>
> >It's important to remember that the Servlet Specification target
> >audience isn't application developers -- it's people that are
> >implementing servlet containers (such as the group that creates
> >Tomcat). It is about defining requirements, not illustrating use
> >cases.
> >
> >For application level questions, and especially for beginners, you'll
> >find any of the plethora of books, magazine articles, tutorials, and
> >mailing lists that are available to be somewhat more accessible.
> >(Personally, I still agree with your PS about the spec being "required
> >reading" -- just need to set your expectations correctly :-).
> >
> >As for your specific question about accessing a context init
> >parameter, you do have it right.
> >
> >Craig
> >
> >
> >On Wed, 24 Nov 2004 14:26:23 -0500, Erik Weber <er...@mindspring.com> wrote:
> >
> >
> >>Well, I have to criticize my own advice. I just read over the Servlet
> >>2.4 spec. It doesn't explain this well at all, in my opinion. It still
> >>uses the same old, nearly meaningless, obscure language like "used by
> >>the Servlet container to communicate with a Servlet", and stuff like
> >>that, which doesn't help anyone who actually wants to write a program.
> >>It does mention the getInitParameter methods of ServletContext and
> >>ServletConfig, but nowhere that I could find does it simply say, use one
> >>with this element in web.xml and the other with that element in web.xml,
> >>and/or why you would choose one or the other.
> >>
> >>Why can't the spec just say what I wrote below instead of trying to be
> >>so "conceptual"? Is what I wrote wrong? This is the stuff that .NET
> >>people criticize and that frustrates new programmers (in my experience).
> >>
> >>Here is a partial outline of how it should be explained:
> >>
> >>Initializing a Servlet
> >>-------------------------
> >>
> >>I. Initialization parameter that is global to your Web application (all
> >>Servlets)
> >>
> >>A. web.xml
> >>
> >><web-app>
> >> . . .
> >> <context-param>
> >> <param-name>globalDateFormatString</param-name>
> >> <param-value>yyyy-MM-dd</param-value>
> >> </context-param>
> >> . . .
> >></web-app>
> >>
> >>B. Java
> >>
> >>// store the date format String, but not a DateFormat,
> >>// as an instance variable or class variable
> >>// (DateFormat can't always be used concurrently)
> >>protected String globalDateFormatString;
> >>. . .
> >>public void init() throws ServletException, UnavailableException {
> >> globalDateFormatString =
> >>getServletContext().getInitParameter("globalDateFormatString");
> >> // try to instantiate a SimpleDateFormat with the String;
> >> // if the String is invalid, throw an Exception to make the Servlet
> >>unavailable
> >>}
> >>
> >>II. Initialization parameter that is specific to one Servlet
> >>
> >>A. web.xml
> >>
> >><servlet>
> >> . . .
> >> <init-param>
> >> <param-name>specificDateFormatString</param-name>
> >> <param-value>|EEE, d MMM yyyy HH:mm:ss Z|</param-value>
> >> </init-param>
> >> . . .
> >></servlet>
> >>
> >>B. Java
> >>
> >>protected String specificDateFormatString;
> >>. . .
> >>public void init() throws ServletException, UnavailableException {
> >> globalDateFormatString =
> >>getServletConfig().getInitParameter("specificDateFormatString");
> >>}
> >>
> >>Please correct me if I have it wrong, or show me the light if I missed
> >>something in the spec. I know I learned this somewhere, but can't
> >>remember where (the tutorial maybe?).
> >>
> >>Shouldn't this be the way the spec reads, or does this type of example
> >>belong somewhere else?
> >>
> >>Erik
> >>
> >>P.S. The spec is still required reading. ;-)
> >>
> >>
> >>
> >>
> >>Bill Siggelkow wrote:
> >>
> >>
> >>
> >>>Thanks for the clarification, Erik.
> >>>
> >>>Erik Weber wrote:
> >>>
> >>>
> >>>
> >>>>I think you want ServletContext.getInitParameter here. That is used
> >>>>with the "context-param" element (global to your web app).
> >>>>ServletConfig.getInitParameter is used with the "init-param" element
> >>>>(specific to one Servlet).
> >>>>
> >>>>In addition to the JavaDocs, you should read the Servlet
> >>>>specification, which tells you how Servlets and Servlet containers
> >>>>are supposed to work. Trust me, it is required reading:
> >>>>
> >>>>http://www.jcp.org/aboutJava/communityprocess/final/jsr154/
> >>>>
> >>>>Erik
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>Bill Siggelkow wrote:
> >>>>
> >>>>
> >>>>
> >>>>>MyServlet extends HttpServlet {
> >>>>>public void init (ServletConfig config) {
> >>>>>String paramValue = config.getInitParameter("myContextParamName");
> >>>>>}
> >>>>>}
> >>>>>
> >>>>>Personally, I have found the JavaDocs invaluable for this kind of
> >>>>>stuff; you can find the Servlet 2.4 Javadocs online at
> >>>>>http://jakarta.apache.org/tomcat/tomcat-5.0-doc/servletapi/index.html.
> >>>>>
> >>>>>-Bill Siggelkow
> >>>>>
> >>>>>Nishant wrote:
> >>>>>
> >>>>>
> >>>>>
> >>>>>>hi
> >>>>>>can anyone tell me how can i get context-param parameter in my
> >>>>>>servlet .
> >>>>>>thanks in advance
> >>>>>>Regards
> >>>>>>Nishant Patil
> >>>>>>Software Engineer
> >>>>>>Cybage Softwares Pvt. Ltd. (A CMM Level 3 Company)
> >>>>>>West Avenue, Kalyaninagar
> >>>>>>Pune - 411006
> >>>>>>Ph. +91-20-4044700/4041700 Extn 355
> >>>>>>nishantp@cybage.com
> >>>>>>www.cybage.com
> >>>>>>"There is difference between knowing the Path and walking on the Path"
> >>>>>>
> >>>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>---------------------------------------------------------------------
> >>>>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>>>For additional commands, e-mail: user-help@struts.apache.org
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>>For additional commands, e-mail: user-help@struts.apache.org
> >>>
> >>>
> >>>
> >>>
> >>
> >>
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >For additional commands, e-mail: user-help@struts.apache.org
> >
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] how do i get context-param
Posted by Erik Weber <er...@mindspring.com>.
Good point. I guess the J2EE tutorial would be the place for stuff like
that (I was trying to only speak of "official" documentation).
Erik
Craig McClanahan wrote:
>It's important to remember that the Servlet Specification target
>audience isn't application developers -- it's people that are
>implementing servlet containers (such as the group that creates
>Tomcat). It is about defining requirements, not illustrating use
>cases.
>
>For application level questions, and especially for beginners, you'll
>find any of the plethora of books, magazine articles, tutorials, and
>mailing lists that are available to be somewhat more accessible.
>(Personally, I still agree with your PS about the spec being "required
>reading" -- just need to set your expectations correctly :-).
>
>As for your specific question about accessing a context init
>parameter, you do have it right.
>
>Craig
>
>
>On Wed, 24 Nov 2004 14:26:23 -0500, Erik Weber <er...@mindspring.com> wrote:
>
>
>>Well, I have to criticize my own advice. I just read over the Servlet
>>2.4 spec. It doesn't explain this well at all, in my opinion. It still
>>uses the same old, nearly meaningless, obscure language like "used by
>>the Servlet container to communicate with a Servlet", and stuff like
>>that, which doesn't help anyone who actually wants to write a program.
>>It does mention the getInitParameter methods of ServletContext and
>>ServletConfig, but nowhere that I could find does it simply say, use one
>>with this element in web.xml and the other with that element in web.xml,
>>and/or why you would choose one or the other.
>>
>>Why can't the spec just say what I wrote below instead of trying to be
>>so "conceptual"? Is what I wrote wrong? This is the stuff that .NET
>>people criticize and that frustrates new programmers (in my experience).
>>
>>Here is a partial outline of how it should be explained:
>>
>>Initializing a Servlet
>>-------------------------
>>
>>I. Initialization parameter that is global to your Web application (all
>>Servlets)
>>
>>A. web.xml
>>
>><web-app>
>> . . .
>> <context-param>
>> <param-name>globalDateFormatString</param-name>
>> <param-value>yyyy-MM-dd</param-value>
>> </context-param>
>> . . .
>></web-app>
>>
>>B. Java
>>
>>// store the date format String, but not a DateFormat,
>>// as an instance variable or class variable
>>// (DateFormat can't always be used concurrently)
>>protected String globalDateFormatString;
>>. . .
>>public void init() throws ServletException, UnavailableException {
>> globalDateFormatString =
>>getServletContext().getInitParameter("globalDateFormatString");
>> // try to instantiate a SimpleDateFormat with the String;
>> // if the String is invalid, throw an Exception to make the Servlet
>>unavailable
>>}
>>
>>II. Initialization parameter that is specific to one Servlet
>>
>>A. web.xml
>>
>><servlet>
>> . . .
>> <init-param>
>> <param-name>specificDateFormatString</param-name>
>> <param-value>|EEE, d MMM yyyy HH:mm:ss Z|</param-value>
>> </init-param>
>> . . .
>></servlet>
>>
>>B. Java
>>
>>protected String specificDateFormatString;
>>. . .
>>public void init() throws ServletException, UnavailableException {
>> globalDateFormatString =
>>getServletConfig().getInitParameter("specificDateFormatString");
>>}
>>
>>Please correct me if I have it wrong, or show me the light if I missed
>>something in the spec. I know I learned this somewhere, but can't
>>remember where (the tutorial maybe?).
>>
>>Shouldn't this be the way the spec reads, or does this type of example
>>belong somewhere else?
>>
>>Erik
>>
>>P.S. The spec is still required reading. ;-)
>>
>>
>>
>>
>>Bill Siggelkow wrote:
>>
>>
>>
>>>Thanks for the clarification, Erik.
>>>
>>>Erik Weber wrote:
>>>
>>>
>>>
>>>>I think you want ServletContext.getInitParameter here. That is used
>>>>with the "context-param" element (global to your web app).
>>>>ServletConfig.getInitParameter is used with the "init-param" element
>>>>(specific to one Servlet).
>>>>
>>>>In addition to the JavaDocs, you should read the Servlet
>>>>specification, which tells you how Servlets and Servlet containers
>>>>are supposed to work. Trust me, it is required reading:
>>>>
>>>>http://www.jcp.org/aboutJava/communityprocess/final/jsr154/
>>>>
>>>>Erik
>>>>
>>>>
>>>>
>>>>
>>>>Bill Siggelkow wrote:
>>>>
>>>>
>>>>
>>>>>MyServlet extends HttpServlet {
>>>>>public void init (ServletConfig config) {
>>>>>String paramValue = config.getInitParameter("myContextParamName");
>>>>>}
>>>>>}
>>>>>
>>>>>Personally, I have found the JavaDocs invaluable for this kind of
>>>>>stuff; you can find the Servlet 2.4 Javadocs online at
>>>>>http://jakarta.apache.org/tomcat/tomcat-5.0-doc/servletapi/index.html.
>>>>>
>>>>>-Bill Siggelkow
>>>>>
>>>>>Nishant wrote:
>>>>>
>>>>>
>>>>>
>>>>>>hi
>>>>>>can anyone tell me how can i get context-param parameter in my
>>>>>>servlet .
>>>>>>thanks in advance
>>>>>>Regards
>>>>>>Nishant Patil
>>>>>>Software Engineer
>>>>>>Cybage Softwares Pvt. Ltd. (A CMM Level 3 Company)
>>>>>>West Avenue, Kalyaninagar
>>>>>>Pune - 411006
>>>>>>Ph. +91-20-4044700/4041700 Extn 355
>>>>>>nishantp@cybage.com
>>>>>>www.cybage.com
>>>>>>"There is difference between knowing the Path and walking on the Path"
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>>---------------------------------------------------------------------
>>>>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>>>For additional commands, e-mail: user-help@struts.apache.org
>>>>>
>>>>>
>>>>>
>>>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>>>
>>>
>>
>>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] how do i get context-param
Posted by Craig McClanahan <cr...@gmail.com>.
It's important to remember that the Servlet Specification target
audience isn't application developers -- it's people that are
implementing servlet containers (such as the group that creates
Tomcat). It is about defining requirements, not illustrating use
cases.
For application level questions, and especially for beginners, you'll
find any of the plethora of books, magazine articles, tutorials, and
mailing lists that are available to be somewhat more accessible.
(Personally, I still agree with your PS about the spec being "required
reading" -- just need to set your expectations correctly :-).
As for your specific question about accessing a context init
parameter, you do have it right.
Craig
On Wed, 24 Nov 2004 14:26:23 -0500, Erik Weber <er...@mindspring.com> wrote:
> Well, I have to criticize my own advice. I just read over the Servlet
> 2.4 spec. It doesn't explain this well at all, in my opinion. It still
> uses the same old, nearly meaningless, obscure language like "used by
> the Servlet container to communicate with a Servlet", and stuff like
> that, which doesn't help anyone who actually wants to write a program.
> It does mention the getInitParameter methods of ServletContext and
> ServletConfig, but nowhere that I could find does it simply say, use one
> with this element in web.xml and the other with that element in web.xml,
> and/or why you would choose one or the other.
>
> Why can't the spec just say what I wrote below instead of trying to be
> so "conceptual"? Is what I wrote wrong? This is the stuff that .NET
> people criticize and that frustrates new programmers (in my experience).
>
> Here is a partial outline of how it should be explained:
>
> Initializing a Servlet
> -------------------------
>
> I. Initialization parameter that is global to your Web application (all
> Servlets)
>
> A. web.xml
>
> <web-app>
> . . .
> <context-param>
> <param-name>globalDateFormatString</param-name>
> <param-value>yyyy-MM-dd</param-value>
> </context-param>
> . . .
> </web-app>
>
> B. Java
>
> // store the date format String, but not a DateFormat,
> // as an instance variable or class variable
> // (DateFormat can't always be used concurrently)
> protected String globalDateFormatString;
> . . .
> public void init() throws ServletException, UnavailableException {
> globalDateFormatString =
> getServletContext().getInitParameter("globalDateFormatString");
> // try to instantiate a SimpleDateFormat with the String;
> // if the String is invalid, throw an Exception to make the Servlet
> unavailable
> }
>
> II. Initialization parameter that is specific to one Servlet
>
> A. web.xml
>
> <servlet>
> . . .
> <init-param>
> <param-name>specificDateFormatString</param-name>
> <param-value>|EEE, d MMM yyyy HH:mm:ss Z|</param-value>
> </init-param>
> . . .
> </servlet>
>
> B. Java
>
> protected String specificDateFormatString;
> . . .
> public void init() throws ServletException, UnavailableException {
> globalDateFormatString =
> getServletConfig().getInitParameter("specificDateFormatString");
> }
>
> Please correct me if I have it wrong, or show me the light if I missed
> something in the spec. I know I learned this somewhere, but can't
> remember where (the tutorial maybe?).
>
> Shouldn't this be the way the spec reads, or does this type of example
> belong somewhere else?
>
> Erik
>
> P.S. The spec is still required reading. ;-)
>
>
>
>
> Bill Siggelkow wrote:
>
> > Thanks for the clarification, Erik.
> >
> > Erik Weber wrote:
> >
> >> I think you want ServletContext.getInitParameter here. That is used
> >> with the "context-param" element (global to your web app).
> >> ServletConfig.getInitParameter is used with the "init-param" element
> >> (specific to one Servlet).
> >>
> >> In addition to the JavaDocs, you should read the Servlet
> >> specification, which tells you how Servlets and Servlet containers
> >> are supposed to work. Trust me, it is required reading:
> >>
> >> http://www.jcp.org/aboutJava/communityprocess/final/jsr154/
> >>
> >> Erik
> >>
> >>
> >>
> >>
> >> Bill Siggelkow wrote:
> >>
> >>> MyServlet extends HttpServlet {
> >>> public void init (ServletConfig config) {
> >>> String paramValue = config.getInitParameter("myContextParamName");
> >>> }
> >>> }
> >>>
> >>> Personally, I have found the JavaDocs invaluable for this kind of
> >>> stuff; you can find the Servlet 2.4 Javadocs online at
> >>> http://jakarta.apache.org/tomcat/tomcat-5.0-doc/servletapi/index.html.
> >>>
> >>> -Bill Siggelkow
> >>>
> >>> Nishant wrote:
> >>>
> >>>> hi
> >>>> can anyone tell me how can i get context-param parameter in my
> >>>> servlet .
> >>>> thanks in advance
> >>>> Regards
> >>>> Nishant Patil
> >>>> Software Engineer
> >>>> Cybage Softwares Pvt. Ltd. (A CMM Level 3 Company)
> >>>> West Avenue, Kalyaninagar
> >>>> Pune - 411006
> >>>> Ph. +91-20-4044700/4041700 Extn 355
> >>>> nishantp@cybage.com
> >>>> www.cybage.com
> >>>> "There is difference between knowing the Path and walking on the Path"
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >>> For additional commands, e-mail: user-help@struts.apache.org
> >>>
> >>>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] how do i get context-param
Posted by Erik Weber <er...@mindspring.com>.
Ack, here I go being a writing critic and leave in a glaring typo . . .
Erik Weber wrote:
> Well, I have to criticize my own advice. I just read over the Servlet
> 2.4 spec. It doesn't explain this well at all, in my opinion. It still
> uses the same old, nearly meaningless, obscure language like "used by
> the Servlet container to communicate with a Servlet", and stuff like
> that, which doesn't help anyone who actually wants to write a program.
> It does mention the getInitParameter methods of ServletContext and
> ServletConfig, but nowhere that I could find does it simply say, use
> one with this element in web.xml and the other with that element in
> web.xml, and/or why you would choose one or the other.
>
> Why can't the spec just say what I wrote below instead of trying to be
> so "conceptual"? Is what I wrote wrong? This is the stuff that .NET
> people criticize and that frustrates new programmers (in my experience).
>
>
> Here is a partial outline of how it should be explained:
>
> Initializing a Servlet
> -------------------------
>
> I. Initialization parameter that is global to your Web application
> (all Servlets)
>
> A. web.xml
>
> <web-app>
> . . .
> <context-param>
> <param-name>globalDateFormatString</param-name>
> <param-value>yyyy-MM-dd</param-value>
> </context-param>
> . . .
> </web-app>
>
> B. Java
>
> // store the date format String, but not a DateFormat,
> // as an instance variable or class variable
> // (DateFormat can't always be used concurrently)
> protected String globalDateFormatString;
> . . .
> public void init() throws ServletException, UnavailableException {
> globalDateFormatString =
> getServletContext().getInitParameter("globalDateFormatString");
> // try to instantiate a SimpleDateFormat with the String;
> // if the String is invalid, throw an Exception to make the Servlet
> unavailable
> }
>
>
>
> II. Initialization parameter that is specific to one Servlet
>
> A. web.xml
>
> <servlet>
> . . .
> <init-param>
> <param-name>specificDateFormatString</param-name>
> <param-value>EEE, d MMM yyyy HH:mm:ss Z</param-value>
> </init-param>
> . . .
> </servlet>
>
> B. Java
>
> protected String specificDateFormatString;
> . . .
> public void init() throws ServletException, UnavailableException {
> globalDateFormatString =
> getServletConfig().getInitParameter("specificDateFormatString");
should be:
specificDateFormatString =
getServletConfig().getInitParameter("specificDateFormatString");
Erik
> }
>
>
>
> Please correct me if I have it wrong, or show me the light if I missed
> something in the spec. I know I learned this somewhere, but can't
> remember where (the tutorial maybe?).
>
> Shouldn't this be the way the spec reads, or does this type of example
> belong somewhere else?
>
> Erik
>
> P.S. The spec is still required reading. ;-)
>
>
>
>
> Bill Siggelkow wrote:
>
>> Thanks for the clarification, Erik.
>>
>> Erik Weber wrote:
>>
>>> I think you want ServletContext.getInitParameter here. That is used
>>> with the "context-param" element (global to your web app).
>>> ServletConfig.getInitParameter is used with the "init-param" element
>>> (specific to one Servlet).
>>>
>>> In addition to the JavaDocs, you should read the Servlet
>>> specification, which tells you how Servlets and Servlet containers
>>> are supposed to work. Trust me, it is required reading:
>>>
>>> http://www.jcp.org/aboutJava/communityprocess/final/jsr154/
>>>
>>> Erik
>>>
>>>
>>>
>>>
>>> Bill Siggelkow wrote:
>>>
>>>> MyServlet extends HttpServlet {
>>>> public void init (ServletConfig config) {
>>>> String paramValue = config.getInitParameter("myContextParamName");
>>>> }
>>>> }
>>>>
>>>> Personally, I have found the JavaDocs invaluable for this kind of
>>>> stuff; you can find the Servlet 2.4 Javadocs online at
>>>> http://jakarta.apache.org/tomcat/tomcat-5.0-doc/servletapi/index.html.
>>>>
>>>> -Bill Siggelkow
>>>>
>>>> Nishant wrote:
>>>>
>>>>> hi
>>>>> can anyone tell me how can i get context-param parameter in my
>>>>> servlet .
>>>>> thanks in advance
>>>>> Regards
>>>>> Nishant Patil
>>>>> Software Engineer
>>>>> Cybage Softwares Pvt. Ltd. (A CMM Level 3 Company)
>>>>> West Avenue, Kalyaninagar
>>>>> Pune - 411006
>>>>> Ph. +91-20-4044700/4041700 Extn 355
>>>>> nishantp@cybage.com
>>>>> www.cybage.com
>>>>> "There is difference between knowing the Path and walking on the
>>>>> Path"
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>>> For additional commands, e-mail: user-help@struts.apache.org
>>>>
>>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: [OT] how do i get context-param
Posted by Erik Weber <er...@mindspring.com>.
Well, I have to criticize my own advice. I just read over the Servlet
2.4 spec. It doesn't explain this well at all, in my opinion. It still
uses the same old, nearly meaningless, obscure language like "used by
the Servlet container to communicate with a Servlet", and stuff like
that, which doesn't help anyone who actually wants to write a program.
It does mention the getInitParameter methods of ServletContext and
ServletConfig, but nowhere that I could find does it simply say, use one
with this element in web.xml and the other with that element in web.xml,
and/or why you would choose one or the other.
Why can't the spec just say what I wrote below instead of trying to be
so "conceptual"? Is what I wrote wrong? This is the stuff that .NET
people criticize and that frustrates new programmers (in my experience).
Here is a partial outline of how it should be explained:
Initializing a Servlet
-------------------------
I. Initialization parameter that is global to your Web application (all
Servlets)
A. web.xml
<web-app>
. . .
<context-param>
<param-name>globalDateFormatString</param-name>
<param-value>yyyy-MM-dd</param-value>
</context-param>
. . .
</web-app>
B. Java
// store the date format String, but not a DateFormat,
// as an instance variable or class variable
// (DateFormat can't always be used concurrently)
protected String globalDateFormatString;
. . .
public void init() throws ServletException, UnavailableException {
globalDateFormatString =
getServletContext().getInitParameter("globalDateFormatString");
// try to instantiate a SimpleDateFormat with the String;
// if the String is invalid, throw an Exception to make the Servlet
unavailable
}
II. Initialization parameter that is specific to one Servlet
A. web.xml
<servlet>
. . .
<init-param>
<param-name>specificDateFormatString</param-name>
<param-value>|EEE, d MMM yyyy HH:mm:ss Z|</param-value>
</init-param>
. . .
</servlet>
B. Java
protected String specificDateFormatString;
. . .
public void init() throws ServletException, UnavailableException {
globalDateFormatString =
getServletConfig().getInitParameter("specificDateFormatString");
}
Please correct me if I have it wrong, or show me the light if I missed
something in the spec. I know I learned this somewhere, but can't
remember where (the tutorial maybe?).
Shouldn't this be the way the spec reads, or does this type of example
belong somewhere else?
Erik
P.S. The spec is still required reading. ;-)
Bill Siggelkow wrote:
> Thanks for the clarification, Erik.
>
> Erik Weber wrote:
>
>> I think you want ServletContext.getInitParameter here. That is used
>> with the "context-param" element (global to your web app).
>> ServletConfig.getInitParameter is used with the "init-param" element
>> (specific to one Servlet).
>>
>> In addition to the JavaDocs, you should read the Servlet
>> specification, which tells you how Servlets and Servlet containers
>> are supposed to work. Trust me, it is required reading:
>>
>> http://www.jcp.org/aboutJava/communityprocess/final/jsr154/
>>
>> Erik
>>
>>
>>
>>
>> Bill Siggelkow wrote:
>>
>>> MyServlet extends HttpServlet {
>>> public void init (ServletConfig config) {
>>> String paramValue = config.getInitParameter("myContextParamName");
>>> }
>>> }
>>>
>>> Personally, I have found the JavaDocs invaluable for this kind of
>>> stuff; you can find the Servlet 2.4 Javadocs online at
>>> http://jakarta.apache.org/tomcat/tomcat-5.0-doc/servletapi/index.html.
>>>
>>> -Bill Siggelkow
>>>
>>> Nishant wrote:
>>>
>>>> hi
>>>> can anyone tell me how can i get context-param parameter in my
>>>> servlet .
>>>> thanks in advance
>>>> Regards
>>>> Nishant Patil
>>>> Software Engineer
>>>> Cybage Softwares Pvt. Ltd. (A CMM Level 3 Company)
>>>> West Avenue, Kalyaninagar
>>>> Pune - 411006
>>>> Ph. +91-20-4044700/4041700 Extn 355
>>>> nishantp@cybage.com
>>>> www.cybage.com
>>>> "There is difference between knowing the Path and walking on the Path"
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>>> For additional commands, e-mail: user-help@struts.apache.org
>>>
>>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
Re: how do i get context-param
Posted by Bill Siggelkow <bi...@bellsouth.net>.
Thanks for the clarification, Erik.
Erik Weber wrote:
> I think you want ServletContext.getInitParameter here. That is used with
> the "context-param" element (global to your web app).
> ServletConfig.getInitParameter is used with the "init-param" element
> (specific to one Servlet).
>
> In addition to the JavaDocs, you should read the Servlet specification,
> which tells you how Servlets and Servlet containers are supposed to
> work. Trust me, it is required reading:
>
> http://www.jcp.org/aboutJava/communityprocess/final/jsr154/
>
> Erik
>
>
>
>
> Bill Siggelkow wrote:
>
>> MyServlet extends HttpServlet {
>> public void init (ServletConfig config) {
>> String paramValue = config.getInitParameter("myContextParamName");
>> }
>> }
>>
>> Personally, I have found the JavaDocs invaluable for this kind of
>> stuff; you can find the Servlet 2.4 Javadocs online at
>> http://jakarta.apache.org/tomcat/tomcat-5.0-doc/servletapi/index.html.
>>
>> -Bill Siggelkow
>>
>> Nishant wrote:
>>
>>> hi
>>> can anyone tell me how can i get context-param parameter in my servlet .
>>> thanks in advance
>>> Regards
>>> Nishant Patil
>>> Software Engineer
>>> Cybage Softwares Pvt. Ltd. (A CMM Level 3 Company)
>>> West Avenue, Kalyaninagar
>>> Pune - 411006
>>> Ph. +91-20-4044700/4041700 Extn 355
>>> nishantp@cybage.com
>>> www.cybage.com
>>> "There is difference between knowing the Path and walking on the Path"
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: how do i get context-param
Posted by Erik Weber <er...@mindspring.com>.
I think you want ServletContext.getInitParameter here. That is used with
the "context-param" element (global to your web app).
ServletConfig.getInitParameter is used with the "init-param" element
(specific to one Servlet).
In addition to the JavaDocs, you should read the Servlet specification,
which tells you how Servlets and Servlet containers are supposed to
work. Trust me, it is required reading:
http://www.jcp.org/aboutJava/communityprocess/final/jsr154/
Erik
Bill Siggelkow wrote:
> MyServlet extends HttpServlet {
> public void init (ServletConfig config) {
> String paramValue = config.getInitParameter("myContextParamName");
> }
> }
>
> Personally, I have found the JavaDocs invaluable for this kind of
> stuff; you can find the Servlet 2.4 Javadocs online at
> http://jakarta.apache.org/tomcat/tomcat-5.0-doc/servletapi/index.html.
>
> -Bill Siggelkow
>
> Nishant wrote:
>
>> hi
>> can anyone tell me how can i get context-param parameter in my servlet .
>> thanks in advance
>> Regards
>> Nishant Patil
>> Software Engineer
>> Cybage Softwares Pvt. Ltd. (A CMM Level 3 Company)
>> West Avenue, Kalyaninagar
>> Pune - 411006
>> Ph. +91-20-4044700/4041700 Extn 355
>> nishantp@cybage.com
>> www.cybage.com
>> "There is difference between knowing the Path and walking on the Path"
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: how do i get context-param
Posted by Bill Siggelkow <bi...@bellsouth.net>.
MyServlet extends HttpServlet {
public void init (ServletConfig config) {
String paramValue = config.getInitParameter("myContextParamName");
}
}
Personally, I have found the JavaDocs invaluable for this kind of stuff;
you can find the Servlet 2.4 Javadocs online at
http://jakarta.apache.org/tomcat/tomcat-5.0-doc/servletapi/index.html.
-Bill Siggelkow
Nishant wrote:
> hi
> can anyone tell me how can i get context-param parameter in my servlet .
> thanks in advance
>
> Regards
> Nishant Patil
> Software Engineer
> Cybage Softwares Pvt. Ltd. (A CMM Level 3 Company)
> West Avenue, Kalyaninagar
> Pune - 411006
> Ph. +91-20-4044700/4041700 Extn 355
> nishantp@cybage.com
> www.cybage.com
> "There is difference between knowing the Path and walking on the Path"
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org