File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Vaibhav Shridish
Greenhorn
Posts: 28
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3695
IntelliJ IDE Java Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
??

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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic