aspose file tools*
The moose likes Servlets and the fly likes Replacing html tags in servlet code with a html file name ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Replacing html tags in servlet code with a html file name ??" Watch "Replacing html tags in servlet code with a html file name ??" New topic
Author

Replacing html tags in servlet code with a html file name ??

Vaibhav Shridish
Greenhorn

Joined: Jun 06, 2002
Posts: 28
Hi
can someone help me solve this problem ?
Problem 1] is there some way i can replace the
out.println statements by directing the control to
another html page.
How do i achieve this ??
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
resp.setContentType("text/html");
PrintWriter out=new PrintWriter(resp.getOutputStream());
String email = req.getParameter("email");
out.println("<HTML>");
out.println("<HEAD>");
out.println("<TITLE>subscribeServlet</TITLE>");
out.println("<BODY><CENTER>");
out.println(email);
if((testemail(email))==true)
{
out.println("<br>");
out.println("Subscription Success");
out.println(req.getRequestURI());
}
else
{
out.println("<br>");
out.println("Failure");
out.println(req.getRequestURI());
}
/*
out.println("Error occured please reenter ur email id");
out.println("<form method="POST" action="http:/\"+"/127.0.0.1:8080/examples/servlet/subscribeServlet4"+"><center>Enter Your Email Address : <input name = "email" value = " " type = "text" size= "40"><br><br><input type="submit" value="Subscribe"><br></center></form>");
*/
out.println("</CENTER></BODY>");
out.println("</HEAD>");
out.println("</HTML>");
out.close();
}[/CODE]

Edited by MC to use UBB Code tags
(oh never mind, it blows up the page)
[ February 21, 2003: Message edited by: Mike Curwen ]

Vaibhav Shridish
Matthew Phillips
Ranch Hand

Joined: Mar 09, 2001
Posts: 2676
There are a couple of ways of doing this. The RequestDispatcher interface has a forward method that will transfer control to an html file without returning to the browser first. The HttpServletResponse interface has a send redirect method that will send a redirect call back to the browser and let the browser know that it should go to the url of the html file.


Matthew Phillips
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I guess, u can use FileStream methods, so that you can parse the text/html file as a char stream and then wrap in a String and append to the writer output.
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

??

Let's not get too fancy.

That's what 'include' is for.

From the tomcat examples app, modify the hello world servlet as follows:


the file included.html, which is located at the root of the application, contains nothing but:And our output is:


If, on the other hand, you want to do some of your processing in the html page, that is "Transfer" the control to that page, because you don't like writing HTML inside out.print() statements (and who does?)... you want a JSP.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Replacing html tags in servlet code with a html file name ??
 
Similar Threads
Internal service error..
Problem regarding redirected error message
servlets using JDBC
HTTP Status 500
form data