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 Forwarding to a HTML page from a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Forwarding to a HTML page from a servlet" Watch "Forwarding to a HTML page from a servlet" New topic
Author

Forwarding to a HTML page from a servlet

Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 573
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

Joined: Mar 22, 2000
Posts: 12761
    
    5
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

Joined: Mar 18, 2004
Posts: 572
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

Joined: Mar 22, 2000
Posts: 12761
    
    5
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
 
 
subject: Forwarding to a HTML page from a servlet
 
Similar Threads
how to call the html form
Calling function with onClick attribute
how to call Http Servlets from other Http Servlets
Preventing html from direct access
Technique for shared servlet data