This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Forwarding to a HTML page from a servlet

 
Tony Evans
Ranch Hand
Posts: 598
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet which does login validation, I want to then either call an error page or call a frame. I am not sure how to call a HTML page from within a servlet.
Is there code or a method that is similar to the getRequestDispatcher.

Thanks Tony
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you will examine the JavaDocs for javax.servlet.RequestDispatcher, you will see that it can be used for any resource - "servlet, HTML file or JSP"
Bill
 
Ali Gohar
Ranch Hand
Posts: 572
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Tony,
There is not benefit of forwarding the request to HTML page. Instead you can use the following code to call the HTML page from your servlet:
response.sendRedirect("/welcome.html");
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
response.sendRedirect does NOT "call the HTML page from your servlet"
It terminates the request by sending a response having the redirect header - the user's browser is then supposed to create a new request to the specified URL.
Forwarding keeps the same request so there is one less request/response cycle.
Bill
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic