Here's what I'm trying to do:
public void init(ServletConfig config) {
// ...
URL url = new URL("http://myhost:port/path/to/otherservlet");
// ... do stuff with contents of url
}
This works fine, but myhost and port are hardcoded and I want to avoid that. I want
URL url = new URL("/path/to/otherservlet");
but that's not valid. I've also tried
config.getServletContext().getResource("/path/to/otherservlet");
but that only works on static files.
How can I use the result of getting one servlet to initialize another? I don't want to use RequestDispatcher's forward() or include() methods -- the results of otherservlet are intended for use in the init() method, not to be sent in the response.