Java HTML page generator
with servlet and without JSP
par Christophe Roux, Franerg
- 8 Septembre 2001


Description of JSIP v1.0

In order to fill the need of dynamic HTML page, I developped my own syntax of inclusion in HTML pages ; I called it JSIP as Java Servlet Include Page. The principle of JSIP uses a tag <SERVLET> of SSI Pages in order to indicate the places where to insert content. But JSIP gives the control of the generation of the page to Servlet.

The servlet loads the JSIP page in memory, analyses it to get the servlet tags labeled at the different places in the page. Then each tag labeled is replaced by dynamic content and the page is sent back by the servlet.

This solution is very simple and short but very powerfull and needs no aditional language. You can find Page.java class which implement this algorithm in the JSIP package com.jsip.

 

Here is an example of HTML code for a " Hello world " servlet :



Attempt of JSIP use


Here is a sample of use of a servlet output.



This show the power of JSIP :


Notice the tag . It indicates the place where to include dynamic part from the servlet in the Web page. This tag has an attribute CODE , showing the name of the dynamic part.

 

The servlet HelloWorld, executing the analysis of the HTML page above, could look like this :

import javax.servlet.*;
import java.servlet.http.*;
import com.jsip.* ;

public class HelloWorld extends HttpServlet {
  public void doGet(HttpServletRequest req, HttpServletResponse res)
throws
  ServletException, IOException) {
    PrintWriter out = res.getWriter();
I   Page p = new Page("HelloWorld.html") ;
    p.put("Hello","Hello World !");
    p.put("ByeBye","ByeBye !");
    out.print(p.toString()) ;
  }
}

  • This servlet allows to separate the source code from the HTML page.
  • Notice the compacity of source code both for HTML part and servlet part.
  • tags can be repeated with the same CODE attribute ; the same dynamic content will be added.
  • If all tags are not defined in the servlet, they will be replaced by blank content in the HTML page.
  • JSIP, this elegant solution is provided under the licence haeding the class Page.java.

 

About Christophe Roux




Les Trucsweb
© 1997-2000 Conception Oznog co. Multimédia
www.trucsweb.com