Hello Michael!
MDV> Hello In java servlets, Im sure there is a way to post all my HTML code with
MDV> the formatting I choose as one string.
MDV> For example
MDV> <html>
MDV> <head>
MDV> <title>My website</title>
MDV> </head>
MDV> <body>
MDV> Welcome to my web site
MDV> </body>
MDV> </html>
MDV> Instead of having to write each seperate line as a string!
Sure you can first stuff all the HTML into a single String or
StringBuffer, but why do you want to do this?
IMO it takes far less resources to emit every string with a
separate write():
when you have
out.write("<html>");
this means that the "<html>" String is a constant and causes no
memory allocation on the servlet execution.
out.write("<html>");
generally results in the string being sent right to the user via
the underling socket implementation without any memory allocation.
Resume:
if you do
out.write("<html>\n");
out.write(" <head>\n");
out.write(" <title>\n");
you have a code that does no memory allocation at run
time at all
if you do
StringBuffer sb=new StringBuffer("<html>\n");
sb.append(" <head>\n"); sb.append(" <title>\n");
out.write(sb.toString());
you explcitly do allocate a StringBuffer() on each
servlet invocation. Why would you want this?
I guess it's reasonable in some special cases, like
precomputing some HTML fragment and caching it in the user
session, but in general
I do advise you to use separate write()-s.
Best regards,
- Anton
[EMAIL PROTECTED]
[EMAIL PROTECTED]
P.S.
BTW: A funny thing, one ECMAScript=JavaScript book I read
on the other hand recommend
document.write("<div><h1>"+stringVariable+"</h1></div>");
over
document.write("<div><h1>"); document.write(stringVariable);
document.write("</h1></div>");
I do not know what is better for ECMAScript=JavaScript, but
for Java IMO separate writes improve performance.
MDV> Thanks in advance,
MDV> Micahel De Vorms
Also when view>>source is selected I want the html to come us as I did it in
MDV> the java code, not in one long line!
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html