¸ð¸£°Ú³×¿ä...servlet¿¡¼­ Ãâ·Â ½ºÆ®¸²ÀÇ ¸·Èû?


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]

±Û¾´ÀÌ :ÃÖ¶õÈñ 2000³â 3¿ù 17ÀÏ 16:46:58

In Reply to: ... posted by ¹æ¹®°´ on 2000³â 3¿ù 16ÀÏ 16:09:52:

À§¿¡¼­ À̾߱âÇϽŠÀÌÀ¯¸¦ ¸ð¸£°Ú³×¿ä...
¾Æ·¡¿Í °°ÀÌ Á¶±Ý º¯ÇüÀ» ½ÃÄ״µ¥..
Á¶±Ý ¾²´Ù°¡ ¸¶´Â ±º¿ä..


//¾²·¹µå·Î html¿¡ ¹«ÇÑÈ÷ ¾²´Â ¹æ½ÄÀ¸·Î ÇÒ·Á°í Çϰŵç¿ä ±×·±µ¥ Áß°£¿¡ ¾²´Ù°¡ ¸¶´Â ±º¿ä...


¿Ö ±×·²±î¿ä..


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;



public class ChatGood extends HttpServlet implements Runnable{

public Vector dialog = new Vector(); // ´ëÈ­ ÀúÀå °ø°£
private String clientMsg = null; //Ŭ¶óÀ̾ðÆ®°¡ ÀÔ·ÂÇÑ ´ëÈ­
private PrintWriter out = null;


public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

out = new PrintWriter(res.getOutputStream(),true);


for(int i = 0; i< 10; i++)
dialog.add("»ç¶ûÇØ");


//¾²°íÀÚ ÇÏ´Â htmlÀ» ÃʱâÈ­, Çì´õ ÀÛ¼º..
initHTML(req, res);

//¾ðÁ¦µçÁö queue¹«¾ùÀÌ ÀÖ´øÁö ²¨³»¼­ ¾²°í ¾ø¾Ø´Ù.

Thread getMsg = new Thread(this);
getMsg.start();

// write(req, res);

}

public void run(){
//test¿ë
if(out == null)
System.out.println("ba bo");
else
System.out.println("ba");

out.println("run<center><BR>");
int count = 0;
while(true){
count++;
out.println("write<center><BR>");
Enumeration queue = dialog.elements();
writeBoard(queue);
System.out.println(count);
}//while

}//RUN

//´ëÈ­ ³»¿ë¿¡ board¿¡ ¾²°Ô µÈ´Ù.
public void writeBoard(Enumeration queue) {

while(queue.hasMoreElements()){
String message = (String)queue.nextElement();
out.print(message + "<BR>");
}

}//writeboard

public void initHTML(HttpServletRequest req, HttpServletResponse res) throws IOException{

// PrintWriter out = new PrintWriter(res.getOutputStream(),true);


res.setContentType("text/html");

out.println("<html><title> servlet example : hello world </title>");
out.println("<body bgcolor=#ffffff><center><BR>");
out.println("dif<center><BR>");

}

public void addMessage(String clientMsg){
dialog.add(clientMsg);
}

public void write(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
PrintWriter toClient = new PrintWriter(res.getOutputStream(),true);


toClient.println("<h1> Hello World </h1><BR><BR>");
toClient.println("<h4> This is servlet's output </h4><BR><BR>");
toClient.println("R U feel ");
toClient.close();
}




}


´ÙÀ½ ±Ûµé:



À̾ ±Û¿Ã¸®±â(´äÇϱâ)

À̸§:
E-Mail:
Á¦¸ñ:
³»¿ë:
HTML ÅÂ±× Æ÷ÇÔ ¿©ºÎ: HTML ¹®¼­ÀÏ °æ¿ì üũ
°ü·Ã URL(¼±ÅÃ):
URL Á¦¸ñ(¼±ÅÃ):
°ü·Ã À̹ÌÁö URL:


[ ´ÙÀ½ ±Ûµé ] [ À̾ ±Û¿Ã¸®±â(´äÇϱâ) ] [ ÀÚ¹Ù ¹¯°í ´äÇϱâ ]