tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Juha Laiho <Juha.La...@iki.fi>
Subject Re: Enable/Disable servlet via context param
Date Wed, 21 Nov 2007 20:52:32 GMT
Matteo Turra wrote:
> I would like enable/disable a servlet depending on a context init
> parameter.

Have a look at the Servlet specification, and therein the
chapter about Servlet Life Cycle.

> I wrote this code in my servlet. But I'm not sure I the best way to do
> it.

> 
> public void init() {
> 
>             String param =
> this.getServletContext().getInitParameter("PARAM");
> 
>             if ("ON".equalsIgnoreCase(param)) {
> 
>                   System.out.println("Servlet: ON");
> 
>                   super.init();     
> 
>             } else {
> 
>                   System.out.println("Servlet: OFF");
> 
>                   this.destroy();
> 
>             }
> 
>       }

I think that might throw things into a kind of loop: the container could
keep on trying to initialize the servlet.

> Any suggestion?

>From the specification (but please get the spec in order to read this in
proper context):

<<<
During initialization, the servlet instance can throw an UnavailableException or a
ServletException. In this case the servlet must not be placed into active service
and must be released by the servlet container. The destroy method is not called as it
is considered unsuccessful initialization.
>>>

-- 
..Juha

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message