Mixer (source, doc, jar, everything) is a simple helper-class (that is easy to use) for Servlet programmers that enable a complete separation of Servlet- and HTML-code. Licence: GNU GPL.
Example | HTML-template | Java-code | HTML-result |
Non repeated |
HTML-document with:
|
Java-code | HTML-document |
Repeated |
HTML-document with:
|
Java-code | HTML-document |
Combined |
HTML-document with:
|
Java-code | HTML-document |
Multiple repeated |
HTML-document with:
|
Java-code | HTML-document |
Adding HTML |
HTML-document 1 with:
|
Java-code | HTML-document |
What are these markers? Context-markers are markers that are placed around parts of HTML-code that should be repeated:
<!---xxx--->
<tr>
<td>
---name---
</td>
<td>
<a href="mailto:---email---">---email---</a>
</td>
</tr>
<!---xxx--->
Variable-markers are markers that should be substituted for values:
<p>
My name is ---name--- and my email is <a href="mailto:---email---">---email---</a>.
</p>
For efficiency use Mixer in a Servlet like this:
Define a class-variable:
private static String htmlTemplate = null;
In method init, load content from a template HTML-file into this class-variable:
if (htmlTemplate == null) {
htmlTemplate = Mixer.getContent(new File(getServletContext().getRealPath("x.html")));
}In metod doGet and/or doPost:
Mixer m = new Mixer(htmlTemplate);
m.add("---email---", "pierre@dsv.su.se");
...
Please report bugs here.
Updated 2002-10-04 by Pierre A. I. Wijkman.