On Thuc Thanh EJB CMB Create Enterprise Application (chọn J2EE 1.4) Chú ý: - Cấu hình CMB: trước tiên delete tất kết nối đến database - URL: jdbc:sqlserver://localhost:1433;databaseName=DEAE - File: JDBCSQL.RAR phải bỏ vào sun=>lib - Start sun server - Vào source packages add databaseName đăng kí microsoft_sqlPool && sunresource lên sun server - Khóa ngoại table phải có khóa - New Timestamp(2011-1900,5,6,0,0,0,0) search theo ngày tháng -1 Cách sử dụng StringTokenizer để cắt chuổi String myCd = req.getParameter("CD"); StringTokenizer t = new StringTokenizer(myCd, "|"); String album = t.nextToken(); String artist = t.nextToken(); String country = t.nextToken(); Cách select liệu từ bảng SalesLocalHome slh = this.lookupSalesBean(); Collection clSales; Iterator it; SalesLocal sl; ProductsLocal pl; CustomersLocal cl; try { clSales = slh.findByAllSales(); it = clSales.iterator(); while (it.hasNext()) { sl = (SalesLocal)it.next(); pl = (ProductsLocal)sl.getProductsBean(); cl = (CustomersLocal)sl.getCustomersBean(); } } catch (FinderException ex) { ex.printStackTrace(); } Code Count Customer CustDetailsLocalHome cus=this.lookupCustDetailsBean2(); try { CustDetailsLocal cuslocal; Collection c=cus.findByAll(); Iterator iter=c.iterator(); int i=0; while(iter.hasNext()) { cuslocal=(CustDetailsLocal)iter.next(); i++; } out.println("Total customer: "+i); }catch (Exception ex){} out.close(); Code Login CustDetailsLocalHome cus =this.lookupCustDetailsBean1(); String id=request.getParameter("id"); String name=request.getParameter("name"); try { CustDetailsLocal cuslocal; Collection c=cus.findByLogin(id,name); Iterator iter=c.iterator(); out.println(c.size()); if(c.size()>0) { cuslocal=(CustDetailsLocal)iter.next(); String cusid= cuslocal.getCustID(); String cusname=cuslocal.getName(); if(cusid.equals(id)&&cusname.equals(name)) { response.sendRedirect("loginsuccess.jsp"); } else { response.sendRedirect("error.jsp"); } } else { response.sendRedirect("error.jsp"); } }catch(Exception ex){} out.close(); Cách Bất JavaScript form nút button onClick=”ruturn Dn_()” Create class khai báo thuộc tính public class CD { private String CUS; private String IDCD; private Double price; public String getCUS() { return CUS; } public void setCUS(String CUS) { this.CUS = CUS; } public String getIDCD() { return IDCD; } public void setIDCD(String IDCD) { this.IDCD = IDCD; } public Double getPrice() { return price; } public void setPrice(Double price) { this.price = price; } } Page Order Code CD: Price: Code add sản phẩm vào cart protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { HttpSession session = req.getSession(false); if (session == null) { res.sendRedirect("error.html"); } Vector buylist = (Vector) session.getAttribute("shoppingcart"); String action = req.getParameter("action"); if (action.equals("ADD")) { boolean match = false; CD aCD = getCD(req); if (buylist == null) { buylist = new Vector(); buylist.addElement(aCD); } else { buylist.addElement(aCD); } session.setAttribute("shoppingcart", buylist); String url=res.encodeRedirectURL("Cart.jsp"); res.sendRedirect(url); } } private CD getCD(HttpServletRequest req) { String iddv = req.getParameter("idDV"); String price = req.getParameter("price"); CD cd = new CD(); cd.setIDCD(iddv); cd.setPrice((new Double(price))); return cd; } Display cart 0)) { %> Cart Of You Identity idDV PRICE Remove No items in cart Back List CD Page Payment JSP Page Bill 0)) { %> Code CD : Price : Total Money: Input Code Customer: Add sản phẩm vào bảng booking in database(code sử lý) BookingDetailsLocalHome bill=this.lookupBookingDetailsBean(); try{ HttpSession session = request.getSession(false); if (session == null) { response.sendRedirect("error.html"); } Vector buylist = (Vector) session.getAttribute("shoppingcart"); if (buylist != null && (buylist.size() >0)) { String kh=request.getParameter("makh"); for (int index=0; index< buylist.size();index++) { // Random rand=new Random(); CD anOrder = (CD) buylist.elementAt(index); String iddv=anOrder.getIDCD(); Double price=anOrder.getPrice(); bill.create((i+1),kh,price,new Timestamp(2011-1900,5-1,6,0,0,0,0)); } } System.out.println("ok!"); }catch (Exception ex){} out.close(); BMP Create driver =>chuột phải vào database chọn new connection =>tạo kết nôi đến database giống CMP JMS JMS Resources => Connection Factories=>new Destination resources= new QUEUE >add gói thư viện imqjmx.jar SendQueueMessage import javax.jms.*; public class SendQueueMessage { public static void main(String args[]) { try { //declare all the local variables QueueConnectionFactory queueConnectionFactory = null; Queue queue = null; QueueConnection queueConnection = null; QueueSession queueSession = null; QueueSender queueSender = null; TextMessage message = null; //lookup for connectionfactory queueConnectionFactory = new com.sun.messaging.QueueConnectionFactory(); //lookup for the destination queue queue = new com.sun.messaging.Queue("sampleQueue"); //create a connection queueConnection = queueConnectionFactory.createQueueConnection(); //create a session queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); //create a sender queueSender = queueSession.createSender(queue); //create a message message = queueSession.createTextMessage(); message.setText("This is a test message!"); //send the message queueSender.send(message); //close the connection queueConnection.close(); System.out.println("Message has been sent to the MQ"); } catch(JMSException e) { System.out.println(e); } } } ReceiveQueueMessage import javax.jms.*; public class ReceiveQueueMessage { public static void main(String args[]) { try { //declare all the local variables QueueConnectionFactory queueConnectionFactory = null; Queue queue = null; QueueConnection queueConnection = null; QueueSession queueSession = null; QueueReceiver queueReceiver = null; TextMessage message = null; //lookup for connectionfactory queueConnectionFactory = new com.sun.messaging.QueueConnectionFactory(); //lookup for the destination queue queue = new com.sun.messaging.Queue("sampleQueue"); //create a connection queueConnection = queueConnectionFactory.createQueueConnection(); //create a session queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); //create a receiver queueReceiver = queueSession.createReceiver(queue); //start the connection queueConnection.start(); //wait for a message message = (TextMessage) queueReceiver.receive(); System.out.println("Received message : "+ message.getText()); //close the connection queueConnection.close(); } catch(JMSException e) { System.out.println(e); } } } ReceiveQueueMessage2 import java.io.*; import javax.jms.*; public class ReceiveQueueMessage2 { public static void main(String args[]) { try { //declare all the local variables QueueConnectionFactory queueConnectionFactory = null; Queue queue = null; QueueConnection queueConnection = null; QueueSession queueSession = null; QueueReceiver queueReceiver = null; TextMessage message = null; TextListener listener = null; //lookup for connectionfactory queueConnectionFactory = new com.sun.messaging.QueueConnectionFactory(); //lookup for the destination queue queue = new com.sun.messaging.Queue("sampleQueue"); //create a connection queueConnection = queueConnectionFactory.createQueueConnection(); //create a session queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); //create a receiver queueReceiver = queueSession.createReceiver(queue); //register the listener listener = new TextListener(); queueReceiver.setMessageListener(listener); queueConnection.start(); //wait for user input to terminate InputStreamReader console = new InputStreamReader(System.in); char ans = (char)console.read(); if(ans == 'q' || ans == 'Q') queueConnection.close(); } catch(JMSException e) { System.out.println(e); } catch(IOException e) { System.out.println(e); } } } class TextListener implements MessageListener { public void onMessage(Message msg) { try{ TextMessage message = (TextMessage) msg; System.out.println("Message Received : "+ message.getText()); } catch(JMSException j){ System.out.println("Exception:"+j.toString()); } } } Topic PublishTopicMessage import javax.jms.*; public class PublishTopicMessage { public static void main(String[] args) { try { //declare all local variables TopicConnectionFactory topicConnectionFactory = null; Topic topic = null; TopicConnection topicConnection = null; TopicSession topicSession = null; TopicPublisher topicPublisher = null; TextMessage message = null; //lookup for connectionfactory topicConnectionFactory = new com.sun.messaging.TopicConnectionFactory(); //lookup for the destination queue topic = new com.sun.messaging.Topic("sampleTopic"); //create a connection topicConnection = topicConnectionFactory.createTopicConnection(); //create a session topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); //create a publisher topicPublisher = topicSession.createPublisher(topic); //create a message message = topicSession.createTextMessage(); message.setText("This is a test message!"); //publish the message topicPublisher.publish(message); //close the connection topicConnection.close(); } catch (JMSException e) { System.out.println(e); } } } SubscribeTopicMessage import javax.jms.*; public class SubscribeTopicMessage { public static void main(String[] args) { try { //declare all local variables TopicConnectionFactory topicConnectionFactory = null; Topic topic = null; TopicConnection topicConnection = null; TopicSession topicSession = null; TopicSubscriber topicSubscriber = null; TextListener listener = null; //lookup for connectionfactory topicConnectionFactory = new com.sun.messaging.TopicConnectionFactory(); //lookup for the destination queue topic = new com.sun.messaging.Topic("sampleTopic"); //create a connection topicConnection = topicConnectionFactory.createTopicConnection(); //create a session topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE); //create a subscriber topicSubscriber = topicSession.createSubscriber(topic); //create a listener listener = new TextListener(); //register the listener topicSubscriber.setMessageListener(listener); topicConnection.start(); //wait for user input to terminate InputStreamReader console = new InputStreamReader(System.in); char ans = (char)console.read(); if(ans == 'q' || ans == 'Q') topicConnection.close(); } catch(JMSException e) { System.out.println(e); } catch(IOException e) { System.out.println(e); } } } class TextListener implements MessageListener { public void onMessage(Message msg) { try{ TextMessage message = (TextMessage) msg; System.out.println("Message Received : "+ message.getText()); } catch (JMSException j){ System.out.println("Exception:"+j.toString()); } } } MDB tạo project enterprise Code sevrlet send message InitialContext ic; try { ic = new InitialContext(); QueueConnectionFactory fact = (QueueConnectionFactory)ic.lookup("jms/NewMessageDestinationFactory"); Queue queue = (Queue)ic.lookup("jms/NewMessageBean"); QueueConnection = fact.createQueueConnection(); QueueSession session = con.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); TextMessage msg = session.createTextMessage(); MessageProducer producer = session.createProducer(queue); for(int i=1; iAddText public String AddText(String text) { return text; }