• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
What's brown and sticky? ... a stick. Or a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic