Could you please hepl in finding, How many ways we can call Statis HTML page from aservlet. Through Request Dispatcher can we forwqaqrd the request to Static HTML ? Please explain me with samle code
John, there are many ways of achieving this, but you must select one which is relevant to your need.
You can use RequestDispatcher's forward to forward to a static html page.
You can also redirect to a static html - but again depends on what you are trying to achieve.
If your servlet prints some statements and you just want to include the static html as part of your display page, you can also try RequestDispatcher's include action
SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD
Forwarding can be used to forward to JSP page or other servlet which processes the forwarded request... No use of forwarding request to static HTML...And redirection is also a costly operation for static stuffs... Instead of that, "include" can be used...
@Ram: Again one point here - forward or include - it depends on the need of your application. If you do not wish to handle the request at all, you'd do a redirect or for partial handling a forward. Though your static page would not really do much of the request object, yet things like the headers, cookies, etc are read by your browser and these could be modified by servlet before the request is forwarded.
Ok... When no processing of request is done at static HTML, why forwarding is needed... response headers, cookies can be configured in servlet and that same servlet can send the static HTML response in output stream or "include" using RequestDispatcher...
Forwarding prevents any static pages from being addressed directly, and/or to simply be organized with all the other JSP views. You can also choose to redirect if the static resource is in an addressable location. The point is, just because a resource is static does not mean that a redirect is the only option -- a forward can also be used if desired.