Simple forum implementation


for checking this example just download these files and replace 'your_host' with the real name.
For running: http://your_host/servlet/alaJSP?forum.htm

<CENTER><B> alaJSP forum </B></CENTER>
<br>
<br>
<!-- load main class, if it is not loaded -->
<%=unique global new Forum() %>
<!-- add new announce -->
<%=Forum.add("<%=stdlib.HTML(what)%>")%>
<!-- output all data -->
<%=Forum.get()%>
<br>
<br>
<form method="post" action="http://your_host/servlet/alaJSP?forum.htm">
<input type="text" name="what" width="30">&nbsp;&nbsp
<input type="Submit" value="Send">
</form>

and this is a java-file:

import java.util.*;

public class Forum
{
  static Vector msg;

  public Forum()
  {
    msg=new Vector();
  }

  public void add(String s)
  {
   if (s.length()>0)
  {
     synchronized (msg)
     {
       msg.addElement(s);
      }
   }
  }

  public String get()
  {
    String ans="";
    int i;

    synchronized (msg)
    {
     for (i=0; i<msg.size(); i++)
       ans+="<br><br>"+(String)msg.elementAt(i);
    }

    return ans;

  }
}
 

Forum.htm  Forum.java

© Dmitry Namiot  ColdJava