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¿¡´ëÇؼ´Â ¾ð±ÞÇÏÁö ¾Ê°í
ÀÖ´Ù.
|