Site Search :
Standard Enterprise XML Methodology Pattern Setting Tunning Other
Article Contributors
GuestBook
Javapattern Maven
XSourceGen Dev
JetSpeed Test
JLook Image
jLook Family Site


Servlet°ú Applet°£ÀÇ HTTP Åë½Å
 
Servlet°ú Applet°£ÀÇ HTTP Åë½ÅÀ» ÀÌ¿ëÇÏ¿© Database ³»¿ëÀ» Applet¿¡ DisplayÇÏ´Â ¹æ¹ý ( 2003/04/02 ) 817
Written by ienvyou - ÃÖÁö¿õ
4 of 4
 

 

MyServlet.java

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


doGet(req,res);


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

res.setContentType("text/html");
ServletOutputStream out = res.getOutputStream();
String command = req.getParameter("name");

if (command == null) {
System.out.println("commnad");
//out.println("Server¿¡ Á¢¼Ó µÇ¼Ì½À´Ï´Ù.");
} else{
ObjectOutputStream oout=new ObjectOutputStream(out);
Object o[]=null;
try{
o=result(out,command);
}catch(Exception ee){System.out.println("DB Error");}
oout.writeObject(o);
}


}


public Object[] result(OutputStream out,String command) throws Exception {


String constr = "jdbc:oracle:thin:@localhost:1521:ORCL";
conn = DriverManager.getConnection(constr, "java","java");
stmt = conn.createStatement();
Vector v=new Vector(1,1);
Object data[]=null;
if(command.equals("Users")){
rset=stmt.executeQuery("SELECT * FROM users");
while(rset.next()){
v.addElement(new UsersEntity(rset.getString(1),rset.getString(2),rset.getString(3)));
}
data=new UsersEntity[v.size()];
v.copyInto(data);

}else if(command.equals("Item")){
rset=stmt.executeQuery("SELECT * FROM item");
while(rset.next()){
v.addElement(new ItemEntity(rset.getString(1),rset.getDouble(2)));
}
data=new ItemEntity[v.size()];
v.copyInto(data);
}
return data;



}

Servlet¿¡¼­´Â Http ProtocolÀ» ÅëÇØ doGet À̳ª doPost method°¡ È£Ã⠵ǾîÁø´Ù.

String command = req.getParameter("name");

Parameter·Î Client·ÎºÎÅÍÀÇ Á¤º¸¸¦ ¹Þ¾Æ¼­

ObjectOutputStream oout=new ObjectOutputStream(out);

ObjectOutputStreamÀ» ¸¸µé°í °á°ú°ªÀ» Client¿¡°Ô Àü´ÞÇÏ°Ô µÈ´Ù.

À§ÀÇ ¿¹Á¦¿¡¼­´Â ConnectionPoolingÀ̳ª Singleton¿¡´ëÇؼ­´Â ¾ð±ÞÇÏÁö ¾Ê°í ÀÖ´Ù.

 

 

3. ½ÇÇà

client side

MyApplet.class

ServletMessage.class

UsersEntity.class

ItemEntity.class

ÀÌ ÆÄÀϵéÀ» ÇϳªÀÇ jar ÆÄÀÏ·Î ¸¸µé°í

jar cvf myapplet.jar MyApplet.class ServletMessage.class UsersEntity.class ItemEntity.class

MyApplet.html

<HTML>
<head>
<title>Phone Applet World</title>
</head>

<body>
<applet archive=myapplet.jar code=MyApplet width=500 height=400>
</applet>
</body>
</HTML>

MyApplet.html ¹®¼­¿Í myapplet.jar µÎ°¡Áö ÆÄÀÏÀ» web serverÀÇ documentation dir¿¡ ³õ´Â´Ù.

server side

MyServlet.class

UsersEntity.class

ItemEntity.class

À̼¼°¡Áö ÆÄÀÏÀ» servlet class°¡ Á¸ÀçÇÏ´Â dir¿¡ ³õ´Â´Ù.

½ÇÇà È­¸é

Users data display

Item data display

 

appletÀÇ È°¿ëµµ°¡ Ä¿Áö¸é¼­ ¿©·¯°¡Áö Á¦¾à »çÇ×ÀÌ ¹ß»ý µÈ´Ù.

ÀÌ·¯ÇÑ »óȲÀ» ServletÀ» ÀÌ¿ëÇÏ¿© ÇØ°áÇÏ´Â ¹æ¹ý¿¡ ´ëÇØ ¾Ë¾Æ º¸¾Ò´Ù.

ÀÌ·¯ÇÑ ¹æ¹ýÀ» ÅëÇϸé serverÁ·¿¡¼­´Â ¿©·¯ port¸¦ ¿­¾î ³õÀ» ÇÊ¿äµµ ¾ø°í º¹ÀâÇÑ middle ware application °³¹ßµµ ÁÙ¾îµç´Ù.

¶ÇÇÑ JSP ³ª ServletÀÇ UI¿¡ ´ëÇÑ ÇѰ踦 appletÀ¸·Î ÇØ°á ÇϹǷμ­ º¸´Ù ´ÙÀ̳ª¹ÍÇÑ webÀ» ±¸ÃàÇÒ¼ö ÀÖ´Ù.

 
1 2 3 4
References
 
Copyright ¨Ï 2003 www.javapattern.info & www.jlook.com, an jLOOK co.,LTD