>>> VINAY KHARE <[EMAIL PROTECTED]> 31-May-00 3:56:36 PM >>>

>I am new in servlet programming .And some one suggested
>me to not to embed html pages in the servlet.what he is
>suggesting is to read it through I/O and put your variables
>in place of some marking (comments in html).he is saying
>that this is best way to do servlet programming  .because it
>separates the logical program away from GUI.and for I/O in
>won't take extra time. because there are separate processor
>for I/O in server .Is it a good way to write servlet or it
>will slow down the execution..???

The way he's suggesting it - yes it will be slower.

I'll explain why:

first method - writing HTML out directly:
1. servlet called when user requests the url
2. servlet obtains a Writer
3. servlet writes output

second method: reading a file and changing values (called a server
side include or SSI)
1. servlet called when user request the url
2. servlet opens a file to print
3. servlet obtains a Writer
4. servlets parses the file to print (from 2) looking for markers to
replace with variables
5. servlet replaces marker with variable when it finds it but writes
the rest to the output


This will be slower because of step 4. The parsing process will take
up some time. If there is a lot of replacement it will be slower than
if there are only a few replacements.

It will also take time to open and read the HTML file - hardware,
operating system and JVM optimizations might make this negligble but I
doubt it.


Your friend is right that it is better to seperate HTML and servlet
logic.

Here are some suggestions:

1. use JSP for displaying your pages
2. use one of the popular template engines (such as WebMacro)
3. use XML and some XSL converter (then it doesn't matter that you
have hardcoded the tags for output coz you can always change the look
by altering the XSL template).



Nic Ferrier

___________________________________________________________________________
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

Reply via email to