hn4u @ Last updated 21/11/04 22:42
Go to my homepage at http://4u.jcisio.com
Full version available at http://4u.jcisio.com/r/article412.htm

Không rõ

Van de cua server-side java va JDBC

(Phuc Nguyen) Toi dang lap trinh su dung java Servlet va JSP, web server la Apache Jserv version 1.1. Toi su dung Connection Pool de quan ly cac ket noi den co so du lieu. Chung hoat dong rat tot. dieu ma toi muon bay gio la lam sao tao mot connection pool phuc vu tat cac cac servet. Dieu nay dan den la connection pool nay phai duoc khoi tao ngay tu khi may ao java khoi dong, va thuc the nay phai ton tai duy nhat trong suot cuoc song cua JVM. nhung toi chua biet lam cach nao. Ai do giup toi voi.

(Nam Tran, VNN1)

Co hai cach ban co the lam chuyen nay:
1. Tao mot A Mini-Application Server bang servlet
Developing Scalable, Reliable, Business Applications with Servlets
by Oz Lubling and Leonardo Malave of Razorfish Building on this concept of a servlet as application server, we developed our application as a group of separate, but interconnected modules that the servlets instantiate dynamically upon request. The main servlet handles connection to the databases and user authentication for all modules. When the main servlet receives a request, it determines which module is to be loaded. The module is always the first parameter in the request, so a request looks like:  /servlet/MyServlet?module=mymodule& ....,and then dynamically instantiates the module simply by using the module's name. The code to do this is included below.
Every module is a subclass of the abstract class mModule. The mModule object includes the setParameter method (which simply passes along the request, response, userid, database connection, and logfile to the newly instantiated module), and the virtual method process, which is where the module must generate an HTML response to the request it received through setParameter. The task of the servlet's HTTP request handling methods, doGet and doPost, is then to simply instantiate the requested module, pass it the necessary parameters, and invoke its process method, as shown below:        // instantiate an object of the requested module
mModule mm = null;
      try {
        Class c = Class.forName( "com.razorfish.app."
                                 + (String)appModules.get(module) );
        mm = (mModule) c.newInstance();
      } catch (IllegalArgumentException iaex) {
        printError(res, "Specified module not found");
        return;
      }
      // pass request parameters to the appropriate module and go       mm.setParams(request, response, user_id, database_connection,
log_file);
      mm.process();
Voi cach nay, ban co the chi dung mot JDBC Connection pool tai Application Servlet boi vi thuc chat theo mo hinh nay ban chi su dung mot hoac nhieu lam la 4 servlet con moi mot trang web se duoc anh xa den mot module. De giup ban co the de dang tham khao them, ban co the dang ky la mot thanh vien developer tai www.javasoft.com, sau do ban co the tham khao cac article (Rat tiec toi khong con nho chinh xac ten article nhu toi da post o tren).2. Tao mot servlet goi la dispatching servlet dung de nhan va forward cac request den mot EJB server. EJB server nay co nhiem vu xu ly tat ca cac request JDBC den Database va vi vay ban chi xu ly cac xu ly den database chi o mot noi do do ban cung chi can mot JDBC Connection Pool o tai EJB server ma thoi. De tim hieu chi tiet hon ve ky thuat nay, ban hay vao site www.iplanet.com va download documents ve iplanet hoac NAS --> no co rat nhieu thong tin bo ich cho ban.Good luck,
Nam Tran
----


hainam4u @ Last updated 21/11/04 22:42
Go to my homepage at http://4u.jcisio.com