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>" );
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."
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!
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.
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
posted
0
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>" );
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