>>> Message UK <[EMAIL PROTECTED]> 9/23/99 1:54:21 PM >>>
>I'm using this code in my servlet for outputting html pages. I'm a
bit
>confused about exactly what is happenening, could someone please
explain
A RequestDispatcher allows you to talk to another servlet in the same
engine as your servlet is running.
Getting an RD (or RequestDispatcher) on a particular path is similar
to a user requesting a servlet path:
There must be a servlet mapped to the path which you create the RD
on. In the case you have used as an example it seem you are probably
using the servlet engines internal web server servlet.
The RD, once created, is a link to the servlet. You can now do one of
2 things:
1. you can include the output from the servlet pointed at by the RD
within output you have generated from your own servlet.
This is very usefull for making servlets into components - eg: having
a database form servlet that just outputs the HTML for the database
form (not the <head> and so on) ad including that in a regular
webpage.
2.you can forward the entire request to the RD servlet which will
mean that your servlet doesn't have to do any output.
Now, in the code you have here:
dispatcher = getServletContext().getRequestDispatcher(html_page);
if (dispatcher==null){
res.sendError(res.SC_NO_CONTENT);
}
try
{
dispatcher.include(req,res);
}
catch (IOException e){}
catch (ServletException e){}
It would seem that you actually want to do a forward(req,res) because
you are not including the RD servlet in any other output.
Imagine this in the try block instead:
{
out.println("<html><body>Hello there... this is a page I thought
you'd like to see...");
dispatcher.include(req,resp);
out.println("hope you enjoyed that... </body></html>");
out.flush();
}
Hope that helps.
Nic
___________________________________________________________________________
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