<%@ page contentType="text/html;charset=GB2312" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*"%>
<HTML>
<BODY bgcolor=cyan><Font size=2 >  
<%!
	Hashtable hashtable=new Hashtable();
     	public synchronized void putString(String s)
     	{ 
		hashtable.put(s,s);
     	}
%>
<%   String person_name=request.getParameter("name"), name_found=null;
         if(person_name==null)
         {
		person_name="";
         }
         byte b[]=person_name.getBytes("ISO-8859-1");
         person_name=new String(b);
%>
<%-- 从文件中读散列表，如果文件不存在，你就是访问本站的第一人，负责写散列表到文件--%>
<% 
	try{ File f=new File("name.txt");
        FileInputStream in=new FileInputStream(f);
        ObjectInputStream object_in=new ObjectInputStream(in);
        hashtable=(Hashtable)object_in.readObject();
        object_in.close();
        in.close();
        name_found=(String)hashtable.get(person_name);
       	if(name_found==null)
          { 
		String person_email=request.getParameter("address");
              	if(person_email==null)
                  {
			person_email="";
                  }
            	StringTokenizer fenxi=new StringTokenizer(person_email,"  @");
            	int n=fenxi.countTokens();
             	if(n>=3)
                 {
			out.print("<BR>"+"你输入的Email有不合法字符");
                 }
             	else
                 { 
			putString(person_name);
                  	try{
                       		FileOutputStream o=new FileOutputStream(f);
                       		ObjectOutputStream object_out=new ObjectOutputStream(o);
                       		object_out.writeObject(hashtable);
                       		object_out.close();
                       		o.close();
                      	   }
                   	catch(Exception eee){}
                  	out.print("<BR>"+"您已经注册成功");
                  	out.print("<BR>"+"您注册的名字是"+person_name);
                   
                }
          }
        else
          {
		out.print("<BR>"+"该名字已经存在，请您换个名字");
          }
         }
    	catch(Exception e)
        {
          	String person_email=request.getParameter("address");
              	if(person_email==null)
                  {
			person_email="";
                  }
            	StringTokenizer fenxi=new StringTokenizer(person_email,"  @");
            	int n=fenxi.countTokens();
             	if(n>=3)
                 {
			out.print("<BR>"+"你输入的Email有不合法字符");
                 }
             	else
                { 
			putString(person_name);
                  	try{ 
				File f=new File("name.txt");
                       		FileOutputStream o=new FileOutputStream(f);
                       		ObjectOutputStream object_out=new ObjectOutputStream(o);
                       		object_out.writeObject(hashtable);
                       		object_out.close();
                       		o.close();
                      	   }
                   	catch(Exception eee){}
                  	out.print("<BR>"+"您是第一个注册成功的人");
                  	out.print("<BR>"+"您注册的名字是"+person_name);
                   
                }
          } 
%>
</BODY>
</HTML>