Servlet °ú Applet»çÀÌ¿¡ Http¸¦ ÅëÇØ ¿¬°áÇÏ´Â ¹æ¹ýÀÔ´Ï´Ù. Servlet¿¡¼´Â
JDBC¸¦ ÀÌ¿ëÇÏ¿© DatabaseÀÇ ³»¿ëÀ» AppletÀÇ ¿äû¿¡ µû¶ó Http ProtocolÀ»
ÀÌ¿ëÇÏ¿© Àü´ÞÇÏ´Â ¹æ¹ýÀÌ´Ù.
±âÁ¸ÀÇ ¹æ¹ý°ú ´Ù¸¥ Á¡Àº Client ÂÊ¿¡¼´Â AppletÀ» ÀÌ¿ëÇÏ¿© º¸´Ù PowerfulÇÑ
UI¸¦ Á¦°ø Çϸ鼵µ Server ÂÊ¿¡¼´Â http Protocol ¸¸À» ÀÌ¿ëÇϱ⶧¹®¿¡ º°µµÀÇ
port¸¦ ÀÌ¿ëÇÏÁö ¾Ê¾Æµµ µÈ´Ù´Â Á¡ÀÌ Æ¯Â¡ÀÌ ÀÖ´Ù.
1. Àüü ³»¿ë
ÀüüÀûÀÎ ±×¸²Àº ´ÙÀ½°ú °°´Ù.
À§ÀÇ ±×¸²À» º¸½Ã¸é ±âÁ¸¿¡ client¿¡¼´Â ´ÜÁö browser¸¦ ÅëÇØ ServletÀ̳ª
jsp¸¦ È£ÃâÀ» ÇÏ´Â ¹æ¹ý¿¡¼ À̹ø¿¡´Â Client¿¡¼ AppletÀ» ÀÌ¿ëÇÏ¿© ServletÀ̳ª
jsp¸¦ È£ÃâÇÏ´Â ¹æ¹ýÀÌ´Ù.
Class±¸Á¶´Â ´ÙÀº°ú °°´Ù.
À§ÀÇ ±×¸²À» º¸¸é Å©°Ô client¿¡¼ ÇÊ¿äÇÑ class µé°ú serverÂÊ¿¡ ÇÊ¿äÇÑ
Class·Î ³ª´©¾î Áø´Ù.
client¿¡¼ ServletÀ» È£ÃâÇÒ¶§´Â POST ¹æ½Ä À̳ª GET¹æ½ÄÀ» ÀÌ¿ëÇÏ°í
Servlet¿¡¼ÀÇ °á°ú°ªÀº ObjectOutputStreamÀ» ÀÌ¿ëÇÏ¿© Client¿¡°Ô
Àü´ÞÇÑ´Ù.
client side
1. MyApplet.java
- ȸé GUI¿Í Event ó¸®
2.
ServletMessage.java - MyApplet¿¡¼ ¹ß»ýÇÏ´Â Event¸¦
POST¹æ½ÄÀ̳ª GET¹æ½ÄÀ¸·Î Servlet¿¡°Ô Message¸¦ Àü´ÞÇÏ°í ±×¿¡´ëÇÑ °á°ú¸¦ ¹Þ¾Æ¼
MyApplet¿¡°Ô Àü´Þ
3. UsersEntity.java
- Users Table¿¡ °üÇÑ Wrapper class
4. ItemEntity.java
- Item Table¿¡ °üÇÑ Wrapper class
server side
1. MyServlet.java
- client¿¡¼ÀÇ message¸¦ http protocol ¹Þ¾Æ¼ ÇöÁ¦ database¿¡¼
data¸¦ ¹Þ¾Æ¿À°í ±×³»¿ë¿¡ ´ëÇÑ °á°ú °ªÀ» UserEntity[] , ItemEntity []
ÇüÅ·Πclient ¿¡°Ô Àü´Þ
2. UsersEntity.java
- Users Table¿¡ °üÇÑ Wrapper class
3. ItemEntity.java
- Item Table¿¡ °üÇÑ Wrapper class
2. source ºÐ¼®
ItemEntity.java
import java.io.*; public class ItemEntity
implements Serializable {
public String item_name; public double
item_price; public ItemEntity(String
item_name,double
item_price){ this.item_name=item_name; this.item_price=item_price; } public
void setItem_name(String
item_name){ this.item_name=item_name; } public
void setItem_price(double
item_address){ this.item_price=item_price; }
public
String getItem_name(){ return
item_name; } public double
getItem_price(){ return
item_price; }
}
|
UsersEntity.java
import java.io.*; public class UsersEntity
implements Serializable {
public String user_id; public String
user_name; public String
user_address; public UsersEntity(String
user_id,String user_name,String
user_address){ this.user_id=user_id; this.user_name=user_name; this.user_address=user_address; } public
void setUser_id(String
user_id){ this.user_id=user_id; } public
void setUser_name(String
user_name){ this.user_name=user_name; } public
void setUser_address(String
user_address){ this.user_address=user_address; } public
String getUser_id(){ return
user_id; } public String
getUser_name(){ return
user_name; } public String
getUser_address(){ return
user_address; }
}
|
À§ÀÇ µÎ°¡Áö class´Â ServerÂÊ¿¡¼ÀÇ °á°ú°ªÀ» client¿¡°Ô Àü´ÞÇÒ¶§ DBÀÇ
dataµéÀ» java obejct typeÀÇ ¹è¿À» ÀÌ¿ëÇÏ¿© Àü´Þ½ÃÅ°´Â wrapper classÀÌ´Ù.
À̶§ °¡Àå Áß¿äÇÑ°ÍÀº µÎ°³ÀÇ object¿¡´Â °´Ã¼ Á÷·ÄÈ°¡ µÇ¾î ÀÖ¾î¾ß ÇÑ´Ù. Áï object
streamÀ» ÅëÇØ °á°ú°ªÀÌ Àü´ÞµÇ±â ¶§¹®¿¡ Ç×»ó java.io.* package°¡
import µÇ¾î¾ß Çϸç implements SerializableÀÌ µÇ¾î¾ß
ÇÑ´Ù.
|