• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How many ways we can call Static HTML page from Servlet

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you can use the request dispatcher. Why don't you just go ahead and try it?
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 247
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ram Narayan.M wrote:No use of forwarding request to static HTML.

Disagree. Why not?
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic