June,
One more thought is that if you are using a container that is using the 2.3
Servlet API, you should use a filter instead of a servlet. It seems that
this is more appropriate since your servlet is not actually ever creating a
response.
public class LogFilter implements Filter {
FilterConfig config;
public void setFilterConfig(FilterConfig config) {
this.config = config;
}
public FilterConfig getFilterConfig() {
return config;
}
public void doFilter(ServletRequest req,
ServletResponse res,
FilterChain chain) {
ServletContext context = getFilterConfig().getServletContext();
long bef = System.currentTimeMillis();
chain.doFilter(req, res); // no chain parameter needed here
long aft = System.currentTimeMillis();
context.log("Request to " + req.getRequestURI() + ": " + (aft-bef));
}
}
..... entries in the web.xml
<filter>
<filter-name>
log
</filter-name>
<filter-class>
LogFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>log</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
This was taken from Jason Hunter's article:
http://www.javaworld.com/javaworld/jw-01-2001/jw-0126-servletapi.html
Regards,
Richard
At 03:59 PM 4/16/2002 -0600, you wrote:
>Hi Michael,
>
>After reading your reply, I thought it seemed to explain the recursive
>call to the EntryServlet, because I do reference other resources like
>images and other JSPs. So, I ran a test, I wrote a very simple html, like
><html><body> can you see this? </body></html>, which does not reference
>anything in the server, and, arrrrrrrrrrrrgh, I still get my debug msg a
>thousand times and I get java.lang.StackOverflowError. It still makes
>that recursive call to the EntryServlet!!!
>
>June
>
>
>On Tue, 16 Apr 2002 12:56:11 +0200, Michael Weller <[EMAIL PROTECTED]> wrote:
>
> >hi!
> >maybe the reason is that in your html you have references to some other
> >resources. if a client loads your html, it also needs to request these
> >other resources (e.g. images, css-files) from your server, your servlet is
> >mapped to get all requests in its context so it also gets those requesting
> >other files. this would explain n calls to your servlet, if n resources are
> >referenced in the html code your servlet served, not thousands of them...
> >
> >hope this helps!
> >
> >-mw
> >
> >At 15:35 16.04.2002 +1000, you wrote:
> >>Hello all,
> >>I wanted to serve everything in the root
> >>directory(html, jsp) through this EntryServlet, in
> >>which I do some counting and various stuff.
> >>
> >>I thought the way to map a servlet to the root was:
> >>
> >><servlet>
> >> <servlet-name>entry</servlet-name>
> >> <servlet-class>common.EntryServlet</servlet-class>
> >></servlet>
> >>
> >><servlet-mapping>
> >> <servlet-name>entry</servlet-name>
> >> <url-pattern>/*</url-pattern>
> >></servlet-mapping>
> >>
> >>
> >>But when I do that, I think it makes recursive call to
> >>itself, because my debug message in doGet message gets
> >>printed on the tomcat console like a thousand times
> >>and tells me that stack overflowed.
> >>
> >>What am I doing wrong?
> >>
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html