/*

 * WebControl.jsp

 * Description : WAS로 데이타를 요청하거나, 보낼때에 사용되어지는 서버페이지이다.

 * 네트워크를 하기 위해서는 서버단이 존재해야 하므로, WAS에서 그 역할을 해준다.

 * 일정한 이벤트 간격으로 데이타를 읽고 쓰기를 계속 반복한다.

 * 현재는 두 사용자가 대결하는 형식을 취하고 있다.

 */

 

<%@ page language="java" contentType="text/html; charset=EUC-KR"

    pageEncoding="EUC-KR"%>

<%@ page import="java.io.*" %>

<%@ page import="java.util.*" %>

<%

   String userid   = request.getParameter("userid");

   String score    = request.getParameter("score");

   String commx    = request.getParameter("commx");

   String commy    = request.getParameter("commy");

   String commdata = request.getParameter("commdata");

 

   if (userid.equals("A"))

   {

      writeFile("HEXAPARTNERA.dat", score + "[DIVIDE]" + commdata);   

      try

      {     

        Vector vLines = readFile("HEXAPARTNERB.dat");

        for (int i = 0; i<vLines.size(); ++i)

        {

           out.print(vLines.get(i).toString());

        }

      }

      catch(FileNotFoundException fnfe)

      {

         out.print("NO");

      }

   }

   else if (userid.equals("B"))

   {

      writeFile("HEXAPARTNERB.dat", score + "[DIVIDE]" + commdata);

      try

      {  

         Vector vLines = readFile("HEXAPARTNERA.dat");

         for (int i = 0; i<vLines.size(); ++i)

         {

            out.print(vLines.get(i).toString());

         }

      }

      catch(FileNotFoundException fnfe)

      {

          out.print("NO");

      }

  }

%>

 

<%!

   public void writeFile(String fileName, String msg)

   {

        if (msg == null)

        {

            msg = "";

        }

      Writer w = null;

      BufferedWriter bw = null;

      PrintWriter pw = null;

      try

      {

         w = new FileWriter(fileName);

         bw = new BufferedWriter(w);

         pw = new PrintWriter(bw);

         pw.println(msg);

         pw.flush();

     }

     catch(Exception e)

     {

        e.printStackTrace();   

     }

     finally

     {

        if (pw != null)

        {

            try

            {

                  pw.close();   

            }

            catch(Exception e1) { }

        }

        if (bw != null)

        {

            try

            {

                bw.close();

            }

            catch(Exception e2) { }

        }

        if (w != null)

        {

            try

            {

                w.close();

            }

            catch(Exception e3) { }

       }

    }  

 }

 

 public Vector readFile(String fileName) throws FileNotFoundException

 {

     Reader r = null;

     BufferedReader br = null;

     Vector vLines = new Vector();

     try

     {

        r = new FileReader(fileName);

        br = new BufferedReader(r);

        String line = "";

        while( (line=br.readLine()) != null )

        {

            vLines.add(line);

        }

    }

    catch(FileNotFoundException fnfo)

    {

        throw new FileNotFoundException();

    }

    catch(Exception e) 

    { 

        e.printStackTrace();

    }

    finally

    {

        if (br != null)

        {

            try

            {

                br.close();

            }

            catch(Exception e1) { }

        }

        if (r != null)

        {

            try

            {

                r.close();

            }

            catch(Exception e2) { }

        }

    }

    return vLines;

 }                                                                                                                        %>

 

 

 

 

 

 

+ Recent posts