File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Large amount of HTML output Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Large amount of HTML output" Watch "Large amount of HTML output" New topic
Author

Large amount of HTML output

Rafael Rangel
Greenhorn

Joined: Jun 18, 2001
Posts: 8
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

Joined: Oct 15, 2000
Posts: 255
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....


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
ken chou
Ranch Hand

Joined: Feb 08, 2001
Posts: 68

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

Joined: May 28, 2001
Posts: 287
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

Joined: Jun 18, 2001
Posts: 8
Thanks guys.
timothy zimmerman
Ranch Hand

Joined: Jun 26, 2001
Posts: 149
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

Joined: Oct 12, 2000
Posts: 21
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

Joined: Oct 12, 2000
Posts: 21
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

Joined: Jul 09, 2001
Posts: 76
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


Rehan Malik
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Large amount of HTML output
 
Similar Threads
Passing web.xml info to servlets
PrintWriter's println not working properly for me
jsp:forward page="/
Writing the output of JSP into a string ?
Servlet css file location