• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How many ways we can call Static HTML page from Servlet

 
John David
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can use the request dispatcher. Why don't you just go ahead and try it?
 
Soniya Ahuja
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ram Narayan.M
Ranch Hand
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ram Narayan.M wrote:No use of forwarding request to static HTML.
Disagree. Why not?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Bear. I do it all the time.
 
Soniya Ahuja
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 247
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic