• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Large amount of HTML output

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a way for a servlet to output a large HTML file with some JavaScript code in it? So far, all the servlet examples that I've seen only output simple HTML (like Hello World). Is there a better way than:
output.println( "<html> . . . large html code with some java script . . .</html>" );
 
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you could use stringbuffers for better memory management or you could use JSP to just use java code on the page when needed and the rest plain javascript and html.
------------------
In Gates we trust. Yeah right....
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

By using Servlet, you can simplify HTML generation by creating a HTML class. Go to: http://www.wrox.com/Books/Book_down.asp?sub_section=1&isbn=1861002777&subject=Java&subject_id=13
download the "Chapter 2 source code", you will see a very good example.
 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to agree with Ken 1000% on this one. Im building a site that has over 800 lines of html for the top banner, links side nav bars & bottom banner/links. I put every thing in 2 class files HTMLTop & HTMLBOT & then instantiate them & call them when needed. I also pass the html title to the method when called along with any Javascript that it may need (several different dcripts are used throughout the site. Its as simple as that, code it once & never have to deal with again! Also makes redesigning a site a thousand times easier........all you have to change is these 2 class files & since everything with the html body is servlet generated & uses CSS all you have to do is make the appropriate changes to you style sheets!
 
Rafael Rangel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys.
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Keep in mind when I ask this that I am just a greenhorn but would make sense to possibly use a jsp and tags? Maybe I am overusing them because I have just started getting in to them but I find them much more flexible than servlets when generating pages with a lot of information.
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, you are right, for big amounts of HTML is better to use JSP pages with tags to minimize the Java code inside of the pages. Servlets should be used mainly to process posts, invoke business logic and then route to JSP pages that actually present the results.

Originally posted by timothy zimmerman:
Keep in mind when I ask this that I am just a greenhorn but would make sense to possibly use a jsp and tags? Maybe I am overusing them because I have just started getting in to them but I find them much more flexible than servlets when generating pages with a lot of information.


 
Edgar Sanchez
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For large amounts of HTML you will go better using a JSP page, process your post with a servlet then forward to a JSP page to present the results.

Originally posted by Rafael Rangel:
Is there a way for a servlet to output a large HTML file with some JavaScript code in it? So far, all the servlet examples that I've seen only output simple HTML (like Hello World). Is there a better way than:
output.println( "<html> . . . large html code with some java script . . .</html>" );


 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Another thing that you could do to increase the download speed for the user is to zip the file and then transmit it. You can check from the headers if the browser supports compressed files and if it does, compress it and then transfer it over and then the files will be automatically decompressed on the client's browser. This might be good if you are doing a LOT of html coding and want the user to get the information as fast as possible
 
If you try to please everybody, your progress is limited by the noisiest fool. And this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic