• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

How to generate HTML file using core Java?????

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am in need of your help. I have a piece of code which reads data from a database and writes it to a flat file. Instead of writing it to a flat file we have to present it in a structured way using HTML.Here I don't know taht I have to create (embed) the whole HTML tags in the program itself or how to generate a HTML file using core Java.This is just to display the output(something like reports in HTML).Please help me folks.This is very urgent.
TIA,
Regards,
Murali
 
Sheriff
Posts: 67695
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd investigate JSP, PHP or other server-side template technology to accomplish this, but, that said, if you insist on generating markup in Java check out the Jakarta ECS project.
With ECS you build up an object DOM in memory, then serialize it to HTML, XHTML or a handful of other markups. Much preferred to building up markup in a string buffer.
hth,
bear
[ November 07, 2002: Message edited by: Bear Bibeault ]
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here is a sample of oututting html from a servlet. as you can see it is not fun. especially when you have quotes inside qoutes inside quotes. that is part of the reason they came up with JSP.


response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head>" +
"<title>MagicShop</title></head>" +
"<body background='../stars.gif'><b><font color='white'>");


more from the same servlet


out.println("You have 10000 </font><font color='yellow'>Gold Pieces </font><font color='white'>" + name +
"<p>Would you like to take a quiz?<br>I will give you 10000 <font color='yellow'>Gold Pieces </font>" +
"<font color='white'>for each correct answer.<p><form>" +
"<input type='button' value='Sure, why not!' on_Click=\"top.frames[1].location='http://www.javaguy.dns2go.com/examples/Quiz.html'\">" +
"<p><input type='button' value='No, I have enough gold.' on_Click=\"parent.location.replace('http://www.javaguy.dns2go.com/examples/MagicItems.html')\"></form>" +
"</b></body></html>");
out.close();
}
}

 
Murali Obla
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks,
Tx for your qucik reply. I'll explain my problem in another context. I want to design a HTML page first. In that I have to map the data which I got from database and then write it to another file and save it as .HTM or .HTML. How will I do that?. Should I have to set some rules like between any delimeters ie #FNAME#,I have to replace it with actual value from the database.
ie #FNAME# --> Murali
Is there any facility (class or package)available for this?.Please let me know if any. Other ideas are welcome.
Thanks,
Murali
 
Bear Bibeault
Sheriff
Posts: 67695
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you are describing is a exactly a "template language".

Is there any facility (class or package)available for this?.Please let me know if any.


Yes, JSP, PHP, XSLT, and so on.
hth,
bear
[ November 08, 2002: Message edited by: Bear Bibeault ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic