Retrieving information about the server in Servlet's init()

Discussions

Web tier: servlets, JSP, Web frameworks: Retrieving information about the server in Servlet's init()

  1. I'm writing a webapp for the Tomcat server.
    In the init()-method I'm starting a MailTimerTask which is periodically sending e-mails containing http-links to my servlet. To generate these links I have to know the server-address + context-path. Can I find them out in the init()-method? If not, at the moment I let the deployer specify this information in the deployment descriptor as context init-parameters. Is this the right place for this kind of info?
    Thanks.
  2. I don't think you can find out the URL of a servlet without taking it from a request, or using a vendor-specific API. You could easily have more than one URL that winds up delegating to the same servlet. You can only find out which URL was used to reach the servlet for a particular request. I'd say keep passing the URL you want to use for the servlet as one of its context parameters.