This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Large amount of HTML output  RSS feed

 
Rafael Rangel
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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>" );
 
Brett Knapik
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • 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....
 
ken chou
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • 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.
 
DC Dalton
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks guys.
 
timothy zimmerman
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • 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.
 
Edgar Sanchez
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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
  • 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>" );

 
Rehan Malik
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • 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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!