Servlets FAQ Page 3 of 31
B. Server Side Includes (SSI).
Use the tag inside your HTML file (and rename it .shtml). The HTML designers will makepretty pages; your servlets will output small pieces of text that get spliced in to the web page by the server.
separates UI (HTML) and code.
You have two possible end paths with SSI: either your servlet outputs many tiny bits of text with no HTML tags, oryour servlet outputs a big bunch of text with embedded HTML tags. In the first case, your code can't take advantage of itsknowledge of the structure of the data -- for example, you can't format an HTML table from a database. In the second case,you're back to hardcoding HTML, thus making it hard to change the look of your pages.
C. Presentation Templates.
This is a good way to put common navigation elements (button bar, credits, etc) on all of your pages. The technology is built in to the Java Web Server, and implemented by several (though not all) of the servletengines.
you don't have to enter in the same common HTML for all the countless pages in your web site.
your servlet code still has to hardcode HTML if it wants to be powerful (see item B, SSI).
it's really cool; you only need a single file to do both UI and layout code; you don't have to type "println" so much.
E. Write your own page parser.
If for some reason you're not happy with the standard mechanisms for doing templates(see B-D above), you can always write your own parser. Seriously. It's not rocket science.
F. HTML Object Model Class Libraries
e.g. htmlKona, XML. With these class libraries, you write code and build an objectmodel, then let the objects export HTML. This doesn't really work for complicated layouts -- and forget about letting yourdesigner use an HTML editor -- but it can be useful when you have a highly dynamic site generating HTML, and you want toautomate the process. Unfortunately, you still have to learn HTML, if only to understand and validate the output. See theReferences section of this FAQ for a listing of some class libraries that can help.
G. Do it all yourself
Develop a database-driven content management system. Think C|Net. It has a lot of standardcontent, but the database is king. HTML designers have little pieces of the page that they can play with, but ultimatelythey're just putting content into a database, and the site (servlet) is generating every page request dynamically. This sort of system is very difficult to design and build, but once you've built it, it can really pay off -- but only if you have dozens of writers, editors, designers, and programmers all working on the same site on an ongoing basis.For a brief list of alternate page template systems, see the References section of this FAQ.
How do I send email from a servlet?
with SMTP classes that make sending email very simple. if you are writing your own servlet you could grab one of the many SMTPimplementations from www.gamelan.com (search for SMTP and java). All the ones I've seen are pretty much the same -- open asocket on port 25 and drop the mail off. so you have to have a mail server running that will accept mail from the machine JServ isrunning on.
Are there any ISPs that will host my servlets?
The Adrenaline Group maintains a list of ISP's who host Java Servlets (http://www.adrenalinegroup.com/jwsisp.html) . Of these, afew have also said that they can host Java applications:
The Sphere (http://www.thesphere.com/)
What is the difference between URL encoding and URL rewriting?URL Encoding
is a process of transforming user input to a CGI form so it is fit for travel across the network -- basically, strippingspaces and punctuation and replacing with escape characters. URL Decoding is the reverse process. To perform these operations, call java.net.URLEncoder.encode() and java.net.URLDecoder.decode() (the latter was (finally!) added to JDK 1.2, aka Java 2).
changing "We're #1!" into "We%27re+%231%21"
is a technique for saving state information on the user's browser between page hits. It's sort of like cookies,only the information gets stored inside the URL, as an additional parameter. The HttpSession API, which is part of theServlet API, sometimes uses URL Rewriting when cookies are unavailable.
changing <A HREF="nextpage.html"> into