top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Using addFilter and addServlet in Tomcat

0 votes
274 views

I'm using Tomcat 7.0.42. Most examples of ServletContext.addFilter() and ServletContext.addServlet() show it being used from a contextInitialized() event handler, however, the Servlet 3.0 spec doesn't limit the use of addServlet/addFilter to contextInitialized() (unless it is in there somewhere and I missed it).

I have successfully used addServlet() from the init() method of a Servlet (e.g. I've dynamically created several servlets from a servlet that I specify in a web.xml), however, I have not successfully been able to use addFilter() from my Servlet init method (although I have done so from a contextInitialized event handler).

My questions are:

1) am I totally off the mark in thinking it is OK to use addServlet() from the the init() method of a Servlet? Should I expect this feature to exist in future releases or is it a side-effect that could disappear at anytime?

2) should I be able to use addFilter() from an init() method or is that crazy.

posted Jul 17, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer
1) am I totally off the mark in thinking it is OK to use addServlet()  from the the init() method of a Servlet?

Yes.

Should I expect this feature to exist in future releases

No.

or is it a side-effect that could disappear at anytime?

Yes.

 2) should I be able to use addFilter() from an init() method

No.

 or is that crazy.

No, but not permitted by the spec.

answer Jul 17, 2013 by anonymous
Similar Questions
+2 votes

I downloaded a website say "test.org" using wget utility. Now I want to deploy in Apache Tomcat 8.0 RC. That I have done it.

But I want to do in this manner that I want to access "test.org" locally from my browser as if I am browsing on the internet because links in the test.org refers to itself. Because when I click any link it goes to
Internet and not to my locally saved website.

Please help

0 votes

I want to change the standard session manager. I added in context.xml the In my netbeans ide 7, I created in source packages of my web application the java class.
When I run my web application, tomcat told me it cannot find my manager. What is the procedure to declare my session manager ?

0 votes

Using tomcat 6.I Always confused with connectionTimeout

The number of milliseconds this *Connector* will wait, after accepting a connection, for the request URI line to be presented. The default value is 60000 (i.e. 60 seconds).

Helpful if anyone can explain.?

Is there any connector parameter where i can set request timeout.?Rather than at application level timeout i want tomcat to timeout after certain period if request taking long time..

+1 vote

For a simple web application, what is the expected delay when switching to new version of an application when using the parallel deployment process? I'm trying to do timings right now with a single Hello World JSP and sometimes there is a delay of up to 4 seconds when the new version of the application is deployed (running 5 users simultaneously using Jmeter with cookies turned off), but other times I don't see this behavior. Does anyone know if it is expected for there to be a slight hiccup in response times when the applications are deployed via parallel deployment? I understand that many applications will have initialization logic and that may cause a delay, but I'm wondering if I should expect tomcat to introduce a very small delay when switching from the old version to the new version and if so, how long should I expect that process to take.

...