You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Mohit Garg <mg...@ggn.aithent.com> on 2003/01/02 12:52:07 UTC

Two instances of servlet gets created

I have startup servlet for which one instance is created as soon as my
tomcat starts. But on the first request to the servlet there is another
instance created. i.e Another time init() is called for the servlet.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: reference to external error-page

Posted by Kris Schneider <kr...@dotech.com>.
I really haven't spent much time integrating Apache and TC, but don't you need
an "ajp13" tacked to the end of JkMount? Assuming the JkMount stuff is okay,
what happens if you change the Host tag in TC's server.xml to:

<Host errorReportValveClass="" ... >

AFAICT, the default error reporter (org.apache.catalina.valves.ErrorReportValve)
is what's dumping the error page output. Perhaps removing the valve will allow
Apache to handle the error.

Quoting Michael Mendelson <mm...@intowndenver.com>:

> 
> > #ErrorDocument 404 /missing.html
> 
> Right, I've got something like this in httpd.conf.  But what I have found
> is
> that if page handling is directed to Tomcat (using JkMount), these
> directives
> are not honored.  In other words, if my mounting looks like:
> 
> ErrorDocument 404 /missing.html
> JkMount /myproject/*.jsp
> 
> If I'm looking for http://mydomain.com/bogus.jsp, then the 404 is handled
> through httpd.
> If I'm looking for http://mydomain.com/myproject/bogus.jsp, then the 404 is
> handled through Tomcat.
> 
> What I would like to do, in simple terms, is to redirect my tomcat errors to
> the
> same page.
> 
> 
> Maybe my httpd.conf is incorrectly configured?
> 
> 
> Michael Mendelson
> In Town Consulting, LLC
> www.intowndenver.com
> 
> > -----Original Message-----
> > From: Kris Schneider [mailto:kris@dotech.com]
> > Sent: Friday, January 03, 2003 10:12 AM
> > To: Tomcat Users List; Michael Mendelson
> > Subject: RE: reference to external error-page
> >
> >
> > If you just want custom error pages for Apache, check out the
> > following snippet
> > from httpd.conf:
> >
> > # Customizable error responses come in three flavors:
> > # 1) plain text 2) local redirects 3) external redirects
> > #
> > # Some examples:
> > #ErrorDocument 500 "The server made a boo boo."
> > #ErrorDocument 404 /missing.html
> > #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
> > #ErrorDocument 402 http://www.example.com/subscription_info.html
> >
> > Quoting Michael Mendelson <mm...@intowndenver.com>:
> >
> > >
> > > Thanks Kris,
> > >
> > > This works fine if the error page is another Tomcat context, but I was
> > > wondering
> > > if there was an elegant way to set this up in the httpd.conf or
> server.xml,
> > > without the need for an error-handling jsp to do the rerouting.
> > >
> > > I will probably just go that route, since it won't be difficult to
> write,
> > > but
> > > further ideas are appreciated.
> > >
> > > Michael Mendelson
> > > In Town Consulting, LLC
> > > www.intowndenver.com
> > >
> > >
> > > > -----Original Message-----
> > > > From: Kris Schneider [mailto:kris@dotech.com]
> > > > Sent: Friday, January 03, 2003 7:18 AM
> > > > To: Tomcat Users List
> > > > Subject: Re: reference to external error-page
> > > >
> > > >
> > > > Well, you can't do it directly with an error page, the <location>
> > > > element's body
> > > > is required to contain an application-relative resource. Since
> > you're using
> > > TC
> > > > 4.x, you could take adavantage of JSTL to do something like:
> > > >
> > > > web.xml:
> > > > <error-page>
> > > >   <error-code>404</error-code>
> > > >   <location>/error/404.jsp</location>
> > > > </error-page>
> > > >
> > > > /error/404.jsp:
> > > > <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
> > > > <c:import url="/error/404.html" context="/otherContext"/>
> > > >
> > > > This is equivalent to using the following in a servlet:
> > > >
> > > > ServletContext foreign =
> getServletContext().getContext("/otherContext");
> > > > RequestDispatcher rd =
> foreign.getRequestDispatcher("/error/404.html");
> > > > rd.include(request, response);
> > > >
> > > > So, the error page is still part of the app, it just imports a
> > > > foreign resource
> > > > to display the error message. Will that work for what you want to do?
> > > >
> > > > Quoting Michael Mendelson <mm...@intowndenver.com>:
> > > >
> > > > >
> > > > > Hello all,
> > > > >
> > > > > I would like to use an error page for certain apache/httpd errors
> as
> > > well
> > > > > as
> > > > > tomcat errors (e.g. 404). In the web.xml file though, the
> directive...
> > > > >
> > > > >
> > > >
> ----------------------------------------------------------------------
> > > > ----------
> > > > >    <error-page>
> > > > > 	<error-code>404</error-code>
> > > > > 	<location>/error/404.html</location>
> > > > >    </error-page>
> > > > >
> > > >
> ----------------------------------------------------------------------
> > > > ----------
> > > > >
> > > > > ...routes me to http://localhost/projectname/error/404.html.
> > > > >
> > > > > How would I route to an error page location that might be on the
> same
> > > > > server,
> > > > > but external to the project?
> > > > >
> > > > > I'm using Apache 1.3.23 and Tomcat 4.1.18 (and mod_jk to route
> requests
> > > to
> > > > > tomcat), if it matters.
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Michael
> > > > >
> > > > >
> > > > >
> > > > > --
> > > > > To unsubscribe, e-mail:
> > > > > <ma...@jakarta.apache.org>
> > > > > For additional commands, e-mail:
> > > > > <ma...@jakarta.apache.org>
> > > > >
> > > >
> > > >
> > > > --
> > > > Kris Schneider <ma...@dotech.com>
> > > > D.O.Tech       <http://www.dotech.com/>
> > > >
> > > > --
> > > > To unsubscribe, e-mail:
> > > <ma...@jakarta.apache.org>
> > > > For additional commands, e-mail:
> > > <ma...@jakarta.apache.org>
> > > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > > <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> > > <ma...@jakarta.apache.org>
> > >
> >
> >
> > --
> > Kris Schneider <ma...@dotech.com>
> > D.O.Tech       <http://www.dotech.com/>
> >
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: reference to external error-page

Posted by Michael Mendelson <mm...@intowndenver.com>.
> #ErrorDocument 404 /missing.html

Right, I've got something like this in httpd.conf.  But what I have found is
that if page handling is directed to Tomcat (using JkMount), these directives
are not honored.  In other words, if my mounting looks like:

ErrorDocument 404 /missing.html
JkMount /myproject/*.jsp

If I'm looking for http://mydomain.com/bogus.jsp, then the 404 is handled
through httpd.
If I'm looking for http://mydomain.com/myproject/bogus.jsp, then the 404 is
handled through Tomcat.

What I would like to do, in simple terms, is to redirect my tomcat errors to the
same page.


Maybe my httpd.conf is incorrectly configured?


Michael Mendelson
In Town Consulting, LLC
www.intowndenver.com

> -----Original Message-----
> From: Kris Schneider [mailto:kris@dotech.com]
> Sent: Friday, January 03, 2003 10:12 AM
> To: Tomcat Users List; Michael Mendelson
> Subject: RE: reference to external error-page
>
>
> If you just want custom error pages for Apache, check out the
> following snippet
> from httpd.conf:
>
> # Customizable error responses come in three flavors:
> # 1) plain text 2) local redirects 3) external redirects
> #
> # Some examples:
> #ErrorDocument 500 "The server made a boo boo."
> #ErrorDocument 404 /missing.html
> #ErrorDocument 404 "/cgi-bin/missing_handler.pl"
> #ErrorDocument 402 http://www.example.com/subscription_info.html
>
> Quoting Michael Mendelson <mm...@intowndenver.com>:
>
> >
> > Thanks Kris,
> >
> > This works fine if the error page is another Tomcat context, but I was
> > wondering
> > if there was an elegant way to set this up in the httpd.conf or server.xml,
> > without the need for an error-handling jsp to do the rerouting.
> >
> > I will probably just go that route, since it won't be difficult to write,
> > but
> > further ideas are appreciated.
> >
> > Michael Mendelson
> > In Town Consulting, LLC
> > www.intowndenver.com
> >
> >
> > > -----Original Message-----
> > > From: Kris Schneider [mailto:kris@dotech.com]
> > > Sent: Friday, January 03, 2003 7:18 AM
> > > To: Tomcat Users List
> > > Subject: Re: reference to external error-page
> > >
> > >
> > > Well, you can't do it directly with an error page, the <location>
> > > element's body
> > > is required to contain an application-relative resource. Since
> you're using
> > TC
> > > 4.x, you could take adavantage of JSTL to do something like:
> > >
> > > web.xml:
> > > <error-page>
> > >   <error-code>404</error-code>
> > >   <location>/error/404.jsp</location>
> > > </error-page>
> > >
> > > /error/404.jsp:
> > > <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
> > > <c:import url="/error/404.html" context="/otherContext"/>
> > >
> > > This is equivalent to using the following in a servlet:
> > >
> > > ServletContext foreign = getServletContext().getContext("/otherContext");
> > > RequestDispatcher rd = foreign.getRequestDispatcher("/error/404.html");
> > > rd.include(request, response);
> > >
> > > So, the error page is still part of the app, it just imports a
> > > foreign resource
> > > to display the error message. Will that work for what you want to do?
> > >
> > > Quoting Michael Mendelson <mm...@intowndenver.com>:
> > >
> > > >
> > > > Hello all,
> > > >
> > > > I would like to use an error page for certain apache/httpd errors as
> > well
> > > > as
> > > > tomcat errors (e.g. 404). In the web.xml file though, the directive...
> > > >
> > > >
> > > ----------------------------------------------------------------------
> > > ----------
> > > >    <error-page>
> > > > 	<error-code>404</error-code>
> > > > 	<location>/error/404.html</location>
> > > >    </error-page>
> > > >
> > > ----------------------------------------------------------------------
> > > ----------
> > > >
> > > > ...routes me to http://localhost/projectname/error/404.html.
> > > >
> > > > How would I route to an error page location that might be on the same
> > > > server,
> > > > but external to the project?
> > > >
> > > > I'm using Apache 1.3.23 and Tomcat 4.1.18 (and mod_jk to route requests
> > to
> > > > tomcat), if it matters.
> > > >
> > > > Thanks,
> > > >
> > > > Michael
> > > >
> > > >
> > > >
> > > > --
> > > > To unsubscribe, e-mail:
> > > > <ma...@jakarta.apache.org>
> > > > For additional commands, e-mail:
> > > > <ma...@jakarta.apache.org>
> > > >
> > >
> > >
> > > --
> > > Kris Schneider <ma...@dotech.com>
> > > D.O.Tech       <http://www.dotech.com/>
> > >
> > > --
> > > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> > >
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >
>
>
> --
> Kris Schneider <ma...@dotech.com>
> D.O.Tech       <http://www.dotech.com/>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: reference to external error-page

Posted by Kris Schneider <kr...@dotech.com>.
If you just want custom error pages for Apache, check out the following snippet
from httpd.conf:

# Customizable error responses come in three flavors:
# 1) plain text 2) local redirects 3) external redirects
#
# Some examples:
#ErrorDocument 500 "The server made a boo boo."
#ErrorDocument 404 /missing.html
#ErrorDocument 404 "/cgi-bin/missing_handler.pl"
#ErrorDocument 402 http://www.example.com/subscription_info.html

Quoting Michael Mendelson <mm...@intowndenver.com>:

> 
> Thanks Kris,
> 
> This works fine if the error page is another Tomcat context, but I was
> wondering
> if there was an elegant way to set this up in the httpd.conf or server.xml,
> without the need for an error-handling jsp to do the rerouting.
> 
> I will probably just go that route, since it won't be difficult to write,
> but
> further ideas are appreciated.
> 
> Michael Mendelson
> In Town Consulting, LLC
> www.intowndenver.com
> 
> 
> > -----Original Message-----
> > From: Kris Schneider [mailto:kris@dotech.com]
> > Sent: Friday, January 03, 2003 7:18 AM
> > To: Tomcat Users List
> > Subject: Re: reference to external error-page
> >
> >
> > Well, you can't do it directly with an error page, the <location>
> > element's body
> > is required to contain an application-relative resource. Since you're using
> TC
> > 4.x, you could take adavantage of JSTL to do something like:
> >
> > web.xml:
> > <error-page>
> >   <error-code>404</error-code>
> >   <location>/error/404.jsp</location>
> > </error-page>
> >
> > /error/404.jsp:
> > <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
> > <c:import url="/error/404.html" context="/otherContext"/>
> >
> > This is equivalent to using the following in a servlet:
> >
> > ServletContext foreign = getServletContext().getContext("/otherContext");
> > RequestDispatcher rd = foreign.getRequestDispatcher("/error/404.html");
> > rd.include(request, response);
> >
> > So, the error page is still part of the app, it just imports a
> > foreign resource
> > to display the error message. Will that work for what you want to do?
> >
> > Quoting Michael Mendelson <mm...@intowndenver.com>:
> >
> > >
> > > Hello all,
> > >
> > > I would like to use an error page for certain apache/httpd errors as
> well
> > > as
> > > tomcat errors (e.g. 404). In the web.xml file though, the directive...
> > >
> > >
> > ----------------------------------------------------------------------
> > ----------
> > >    <error-page>
> > > 	<error-code>404</error-code>
> > > 	<location>/error/404.html</location>
> > >    </error-page>
> > >
> > ----------------------------------------------------------------------
> > ----------
> > >
> > > ...routes me to http://localhost/projectname/error/404.html.
> > >
> > > How would I route to an error page location that might be on the same
> > > server,
> > > but external to the project?
> > >
> > > I'm using Apache 1.3.23 and Tomcat 4.1.18 (and mod_jk to route requests
> to
> > > tomcat), if it matters.
> > >
> > > Thanks,
> > >
> > > Michael
> > >
> > >
> > >
> > > --
> > > To unsubscribe, e-mail:
> > > <ma...@jakarta.apache.org>
> > > For additional commands, e-mail:
> > > <ma...@jakarta.apache.org>
> > >
> >
> >
> > --
> > Kris Schneider <ma...@dotech.com>
> > D.O.Tech       <http://www.dotech.com/>
> >
> > --
> > To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: reference to external error-page

Posted by Michael Mendelson <mm...@intowndenver.com>.
Thanks Kris,

This works fine if the error page is another Tomcat context, but I was wondering
if there was an elegant way to set this up in the httpd.conf or server.xml,
without the need for an error-handling jsp to do the rerouting.

I will probably just go that route, since it won't be difficult to write, but
further ideas are appreciated.

Michael Mendelson
In Town Consulting, LLC
www.intowndenver.com


> -----Original Message-----
> From: Kris Schneider [mailto:kris@dotech.com]
> Sent: Friday, January 03, 2003 7:18 AM
> To: Tomcat Users List
> Subject: Re: reference to external error-page
>
>
> Well, you can't do it directly with an error page, the <location>
> element's body
> is required to contain an application-relative resource. Since you're using TC
> 4.x, you could take adavantage of JSTL to do something like:
>
> web.xml:
> <error-page>
>   <error-code>404</error-code>
>   <location>/error/404.jsp</location>
> </error-page>
>
> /error/404.jsp:
> <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
> <c:import url="/error/404.html" context="/otherContext"/>
>
> This is equivalent to using the following in a servlet:
>
> ServletContext foreign = getServletContext().getContext("/otherContext");
> RequestDispatcher rd = foreign.getRequestDispatcher("/error/404.html");
> rd.include(request, response);
>
> So, the error page is still part of the app, it just imports a
> foreign resource
> to display the error message. Will that work for what you want to do?
>
> Quoting Michael Mendelson <mm...@intowndenver.com>:
>
> >
> > Hello all,
> >
> > I would like to use an error page for certain apache/httpd errors as well
> > as
> > tomcat errors (e.g. 404). In the web.xml file though, the directive...
> >
> >
> ----------------------------------------------------------------------
> ----------
> >    <error-page>
> > 	<error-code>404</error-code>
> > 	<location>/error/404.html</location>
> >    </error-page>
> >
> ----------------------------------------------------------------------
> ----------
> >
> > ...routes me to http://localhost/projectname/error/404.html.
> >
> > How would I route to an error page location that might be on the same
> > server,
> > but external to the project?
> >
> > I'm using Apache 1.3.23 and Tomcat 4.1.18 (and mod_jk to route requests to
> > tomcat), if it matters.
> >
> > Thanks,
> >
> > Michael
> >
> >
> >
> > --
> > To unsubscribe, e-mail:
> > <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> > <ma...@jakarta.apache.org>
> >
>
>
> --
> Kris Schneider <ma...@dotech.com>
> D.O.Tech       <http://www.dotech.com/>
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: reference to external error-page

Posted by Kris Schneider <kr...@dotech.com>.
Well, you can't do it directly with an error page, the <location> element's body
is required to contain an application-relative resource. Since you're using TC
4.x, you could take adavantage of JSTL to do something like:

web.xml:
<error-page>
  <error-code>404</error-code>
  <location>/error/404.jsp</location>
</error-page>

/error/404.jsp:
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<c:import url="/error/404.html" context="/otherContext"/>

This is equivalent to using the following in a servlet:

ServletContext foreign = getServletContext().getContext("/otherContext");
RequestDispatcher rd = foreign.getRequestDispatcher("/error/404.html");
rd.include(request, response);

So, the error page is still part of the app, it just imports a foreign resource
to display the error message. Will that work for what you want to do?

Quoting Michael Mendelson <mm...@intowndenver.com>:

> 
> Hello all,
> 
> I would like to use an error page for certain apache/httpd errors as well
> as
> tomcat errors (e.g. 404). In the web.xml file though, the directive...
> 
> --------------------------------------------------------------------------------
>    <error-page>
> 	<error-code>404</error-code>
> 	<location>/error/404.html</location>
>    </error-page>
> --------------------------------------------------------------------------------
> 
> ...routes me to http://localhost/projectname/error/404.html.
> 
> How would I route to an error page location that might be on the same
> server,
> but external to the project?
> 
> I'm using Apache 1.3.23 and Tomcat 4.1.18 (and mod_jk to route requests to
> tomcat), if it matters.
> 
> Thanks,
> 
> Michael
> 
> 
> 
> --
> To unsubscribe, e-mail:  
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> 


-- 
Kris Schneider <ma...@dotech.com>
D.O.Tech       <http://www.dotech.com/>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


reference to external error-page

Posted by Michael Mendelson <mm...@intowndenver.com>.
Hello all,

I would like to use an error page for certain apache/httpd errors as well as
tomcat errors (e.g. 404). In the web.xml file though, the directive...

--------------------------------------------------------------------------------
   <error-page>
	<error-code>404</error-code>
	<location>/error/404.html</location>
   </error-page>
--------------------------------------------------------------------------------

...routes me to http://localhost/projectname/error/404.html.

How would I route to an error page location that might be on the same server,
but external to the project?

I'm using Apache 1.3.23 and Tomcat 4.1.18 (and mod_jk to route requests to
tomcat), if it matters.

Thanks,

Michael



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Two instances of servlet gets created

Posted by Andreas Probst <an...@gmx.net>.
Hi,

do you call your servlet by the pattern defined in web.xml or by 
the full path with invoker servlet? 

I once read, that using the invoker servlet means creating a new 
instance of your servlet. Maybe that's what causes the second 
init().

Hope this helps

Andreas


On 2 Jan 2003 at 17:22, Mohit Garg wrote:

> I have startup servlet for which one instance is created as soon
> as my tomcat starts. But on the first request to the servlet
> there is another instance created. i.e Another time init() is
> called for the servlet.
> 
> 


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>