General discussion

Locked

servlets

By kellogy22 ·
How to invoke a html file through a servlet?

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by rashmigopinath In reply to servlets

If you have to make a call to the HTML file from your servlet, you would have to use the RequestDispatcher class. You can use either the include() or the forward() method based on your requirement.
Please refer to the Servlet docs for usage information.

Thanks,
Rashmi.

Collapse -

by pra_kie In reply to servlets

simply use, response.sendRedirect(request.getContextPath()+"redirectionfile.htm");
-- this one is absolute fragment type redirection
--this one equvalent to
response.sendRedirect( " /redirectionfile.htm " );


or u can use relative fragment,

response.sendRedirect( "redirectionfile.htm" );

Collapse -

by saurabhambekar In reply to servlets

I would advice you should use RequestDispatcher way and not the response.sendRedirect way. sendRedirect way is not good.

Collapse -

by chellaganesh In reply to servlets

Hi,
If you want to generate Html output from the servlet, you need to write the Html code to the response object.

PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hola</title>");
out.println("</head>");
out.println("<body bgcolor=\"white\">");
out.println("<h1> HelloWorldEJB Says: </h1>");
out.println(this.hw.hi());
out.println("</body>");
out.println("</html>");

If you want to call a HTML file you need to use the RequestDespatcher object

Back to Web Development Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums