File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How many ways we can call Static HTML page from Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How many ways we can call Static HTML page from Servlet" Watch "How many ways we can call Static HTML page from Servlet" New topic
Author

How many ways we can call Static HTML page from Servlet

John David
Greenhorn

Joined: Aug 17, 2006
Posts: 29
Hi folks
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

Regards
David
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

Yes, you can use the request dispatcher. Why don't you just go ahead and try it?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Soniya Ahuja
Ranch Hand

Joined: Jul 20, 2008
Posts: 83
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
http://soniyaahuja.webs.com
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

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...


SCJP 6 [SCJP - Old is Gold]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

Ram Narayan.M wrote:No use of forwarding request to static HTML.
Disagree. Why not?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

I agree with Bear. I do it all the time.
Soniya Ahuja
Ranch Hand

Joined: Jul 20, 2008
Posts: 83
@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.
Ram Narayan.M
Ranch Hand

Joined: Jul 11, 2010
Posts: 247

@Soniya

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...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How many ways we can call Static HTML page from Servlet