The results you see mean that you are running under a relatively modern servlet
engine (one that implements version 2.1 or 2.2 of the servlet specification), in
which cases the getServletNames() method has been deprecated and is required to
return an empty enumeration. This facility was removed (along with getServlet()
and a couple of others) for valid security reasons that have been discussed
extensively on this list and on the SERVLET-INTEREST list.
You will want to investigate using a RequestDispatcher.forward() call -- or the JSP
equivalent <jsp:forward> to accomplish what you are after.
Craig McClanahan
Alex Waltrip wrote:
> Hello fellow coders,
> I'm just getting into servlet programming because I think it's neat, and I'm
> hoping to convert my development team off Oracle PL/SQL (good one, huh)
> procedures that spew html over to servlets, of course none of them listen to
> anything I have to say so since I'm unmarried without children and am a
> liberal, etc...
>
> Anyway, I'm running RedHat linux 6.0/Apache 1.3.9/Jserv 1.1 and am new to
> servlet programming.
>
> Let me describe what I'm trying to do.
>
> I have a servlet named "ResultsHandler" that get's called from my index.html
> web page. I want to call another servlet named "DBAccessServlet" from
> ResultsHandler. From reading Jason Hunter's book "Java Servlet Programming", I
> believe the correct way to do this is:
>
> try {
> out.println("About to call getServletContext()");
> ServletContext context = getServletContext();
> out.println("Done calling getServletContext()");
>
> out.println("About to call getServletNames()");
> Enumeration names = context.getServletNames();
> out.println("Done calling getServletNames()");
>
> out.println("About to iterate through servlet names:");
> while (names.hasMoreElements()) {
> String name = (String) names.nextElement();
> Servlet servlet = context.getServlet(name);
> out.println("Servlet name: " + name);
> out.println("Servlet class: " + servlet.getClass().getName());
> out.println("Servlet info: " + servlet.getServletInfo());
> out.println();
> }
> out.println("What'd we get?");
> }
> catch (Exception e) {
> out.println("Got exception");
> out.println(e.getMessage());
> }
> finally {
> }
>
> When I execute this code (reload the page), I get the following output:
> About to call getServletContext()
> Done calling getServletContext()
> About to call getServletNames()
> Done calling getServletNames()
> About to iterate through servlet names:
> What'd we get?
>
> Shouldn't I at least get the name of the servlet from which this code is
> called, namely, ResultsHandler? I don't get "Got exception" printed out as
> would happen if it caught an exception so I'm assuming that the method is valid
> but there are simply no servlets to be found.
>
> Any advise would be greatly appreciated.
>
> TIA.
> --
> Alex Waltrip
> Denver, Colorado.
> Email: [EMAIL PROTECTED]
>
> ===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets