¿ìËÙÒµÎñͨµÀ

Java EEÓ¦ÓóÌÐòÈëÃÅ - ±à³ÌÈëÃÅÍø

×÷Õß ØýÃû¼¼Êõ À´Ô´ NET±à³Ì ä¯ÀÀ ·¢²¼Ê±¼ä 2012-06-16
bjectMessage) { ¡¡¡¡¡¡¡¡¡¡¡¡ msg = (ObjectMessage) message; ¡¡¡¡¡¡¡¡¡¡¡¡ NewsEntity e = (NewsEntity) msg.getObject(); ¡¡¡¡¡¡¡¡¡¡¡¡ save(e); ¡¡¡¡¡¡¡¡ } ¡¡¡¡ } catch (JMSException e) { ¡¡¡¡¡¡¡¡ e.printStackTrace(); ¡¡¡¡¡¡¡¡ mdc.setRollbackOnly(); ¡¡¡¡ } catch (Throwable te) { ¡¡¡¡¡¡¡¡ te.printStackTrace(); ¡¡¡¡ }

°´Ï Alt-Shift-F ×éºÏ¼ü£¬Éú³ÉËùÓбØÐèµÄµ¼ÈëÓï¾ä¡£ ×¢Ò⣺ Éú³Éµ¼ÈëÓï¾äʱ£¬ÎÒÃÇÐèÒª È·±£µ¼Èë jms ºÍ javax.annotation.Resource ¿â¡£

±£´æÎļþ¡£

´´½¨»á»° Bean

½ÓÏÂÀ´£¬ÎÒÃǽ«Îª NewsEntity ʵÌåÀà´´½¨»á»°Íâ¹Û¡£´´½¨»á»°Íâ¹ÛµÄ²½ÖèÈçÏ£º

ÓÒ»÷ EJB Ä£¿é£¬È»ºóÑ¡Ôñ New > File/Folder ¡£

´Ó Persistence Àà±ðÖУ¬Ñ¡Ôñ Session Beans for Entity Classes £¬È»ºóµ¥»÷ Next °´Å¥¡£

´Ó¿ÉÓÃʵÌåÀàµÄÁбíÖУ¬Ñ¡Ôñ ejb.NewsEntity ²¢µ¥»÷ Add £¬È»ºóµ¥»÷ Next °´Å¥¡£

È·¶¨½« Package ÉèÖÃΪ ejb ²¢ÇÒÒÑ´´½¨±¾µØ½Ó¿Ú¡£

µ¥»÷ Finish °´Å¥¡£

µ¥»÷ Finish °´Å¥ºó£¬IDE ½«»á´´½¨»á»°Íâ¹ÛÀà NewsEntityFacade.java£¬¶øÇÒ¸ÃÀà»áÔÚÔ´´úÂë±à¼­Æ÷Öдò¿ª¡£IDE »¹»á´´½¨±¾µØ½Ó¿Ú NewsEntityFacadeLocal.java¡£

EJB 3.0 ¼¼Êõ¼ò»¯Á˻Ự bean µÄ´´½¨¹ý³Ì£¬ÒòΪËü¼õÉÙÁËËùÐè´úÂëµÄÊýÁ¿¡£Äú¿ÉÒÔ¿´µ½£¬×¢ÊÍ @Stateless ÓÃÓÚ°ÑÀàÉùÃ÷ΪÎÞ״̬µÄ»á»° bean£¬¶øÀ಻ÔÙÐèÒªÒ»ÌõÓï¾äÀ´ÊµÏÖ javax.ejb.SessionBean¡£´úÂëÒ²ÒªÇåÎúºÜ¶à£¬ÒòΪ½èÖú EJB 3.0 ¼¼Êõ£¬ÒµÎñ·½·¨²»ÔÙÐèÒª´úÂëÀ´ÉùÃ÷ËüÃÇÅ׳öÁËδ¾­¼ì²éµÄÒì³£¡£

Äú¿ÉÒÔ¿´µ½£¬´´½¨»á»°Íâ¹Ûʱ£¬ PersistenceContext ×ÊÔ´±»Ö±½Ó×¢ÈëÁ˻Ự bean ×é¼þÖС£

Java EEÓ¦ÓóÌÐòÈëÃÅ(5)

ʱ¼ä:2011-07-06 netbeans.org

С½á

ÔÚ±¾Á·Ï°ÖУ¬ÎÒÃÇΪ EJB Ä£¿éÖеÄÒ»¸öʵÌåÀàºÍÒ»¸öÏûÏ¢Çý¶¯±àдÁË´úÂë¡£ÎÒÃÇ»¹´´½¨ÁËÎÒÃǵÄÓ¦ÓóÌÐò½«»áʹÓÃµÄ JMS ×ÊÔ´¡£

±àд Web Ä£¿é

ÏÖÔÚ£¬ÎÒÃǽ«ÔÚ web Ä£¿éÖд´½¨ servlets ListNews ºÍ PostMessage¡£ÕâЩ servlets ½«ÓÃÓÚ¶ÁÈ¡ºÍÌí¼ÓÏûÏ¢¡£

´´½¨ ListNews Servlet

ÔÚ±¾Á·Ï°ÖУ¬ÎÒÃǽ«´´½¨Ò»¸öÓÃÓÚÏÔʾÊý¾ÝµÄ¼òµ¥ servlet¡£ÎÒÃǽ«Ê¹ÓÃ×¢ÊÍ´ÓÎÒÃÇµÄ servlet Öе÷ÓÃʵÌå¡£

ÓÒ»÷ web Ä£¿éÏîÄ¿£¬È»ºóÑ¡Ôñ New > Servlet ¡£

¼üÈë ListNews ×÷ΪÀàÃû¡£

ÊäÈë web ×÷Ϊ°üÃû£¬È»ºóµ¥»÷ Finish °´Å¥¡£

µ¥»÷ Finish °´Å¥ºó£¬Àà ListNews.java ¾Í»áÔÚÔ´´úÂë±à¼­Æ÷Öдò¿ª¡£ÔÚÔ´´úÂë±à¼­Æ÷ÖУ¬Ö´ÐÐÒÔϲ½Ö裺

ÔÚÔ´´úÂëÔÚµ¥»÷Êó±êÓÒ¼ü£¬È»ºóÑ¡Ôñ Enterprise Resources > Call Enterprise Bean ¡£

ÔÚ Call Enterprise Bean ¶Ô»°¿òÖУ¬Ñ¡Ôñ NewsEntityFacade È»ºóµ¥»÷ OK °´Å¥¡£µ¥»÷ OK °´Å¥ºó£¬ÊµÌå bean Ô´´úÂë¾Í»áͨ¹ýʹÓà @EJB ×¢ÊÍ×¢Èëµ½ servlet ÖС£

ÔÚ processRequest ·½·¨ÖУ¬È¥µô´úÂëµÄ×¢ÊÍ£¬²¢ÔÚ·½·¨ÌåÖÐÌí¼ÓÒÔÏÂÓúÚÌå±íʾµÄÐУºout.println("<h1>Servlet ListNews at " + request.getContextPath () + "</h1>"); List news = newsEntityFacade.findAll(); for (Iterator it = news.iterator(); it.hasNext();) { ¡¡¡¡ NewsEntity elem = (NewsEntity) it.next(); ¡¡¡¡ out.println(" <b>"+elem.getTitle()+" </b><br />"); ¡¡¡¡ out.println(elem.getBody()+"<br /> "); } out.println("<a href=''PostMessage''>Add new message</a>"); out.println("</body>");

°´Ï Alt-Shift-F ×éºÏ¼ü£¬±ã¿ÉΪÀàÉú³ÉËùÓбØÐèµÄµ¼ÈëÓï¾ä¡£Éú³Éµ¼ÈëÓï¾äʱ£¬ÎÒÃÇÐèÒª µ¼Èë java.util ¿â¡£

±£´æ¶ÔÎļþËù×öµÄÐ޸ġ£

´´½¨ PostMessage Servlet

ÔÚ±¾Á·Ï°ÖУ¬ÎÒÃǽ«´´½¨ÓÃÓÚ·¢²¼ÏûÏ¢µÄ PostMessage servlet¡£ÎÒÃÇ

ÁèÖڿƼ¼×¨ÒµÌṩ·þÎñÆ÷×âÓᢷþÎñÆ÷Íйܡ¢ÆóÒµÓʾ֡¢ÐéÄâÖ÷»úµÈ·þÎñ£¬¹«Ë¾ÍøÕ¾£ºhttp://www.lingzhong.cn ΪÁ˸ø¹ã´ó¿Í»§Á˽â¸ü¶àµÄ¼¼ÊõÐÅÏ¢£¬±¾¼¼ÊõÎÄÕÂÊÕ¼¯À´Ô´ÓÚÍøÂç,ÁèÖڿƼ¼×ðÖØÎÄÕÂ×÷ÕߵİæȨ£¬Èç¹ûÓÐÉæ¼°ÄãµÄ°æȨÓбØҪɾ³ýÄãµÄÎÄÕ£¬ÇëºÍÎÒÃÇÁªÏµ¡£ÒÔÉÏÐÅÏ¢ÓëÎÄÕÂÕýÎÄÊDz»¿É·Ö¸îµÄÒ»²¿·Ö,Èç¹ûÄúҪתÔر¾ÎÄÕÂ,Çë±£ÁôÒÔÉÏÐÅÏ¢£¬Ð»Ð»!

·ÖÏíµ½£º ¸ü¶à

Copyright ©1999-2011 ÏÃÃÅÁèÖڿƼ¼ÓÐÏÞ¹«Ë¾ ÏÃÃÅÓÅͨ»¥Áª¿Æ¼¼¿ª·¢ÓÐÏÞ¹«Ë¾ All rights reserved

µØÖ·(ADD)£ºÏÃÃÅÈí¼þÔ°¶þÆÚÍûº£Â·63ºÅ701E£¨¶«ÄÏÈÚͨÅÔ£© Óʱà(ZIP)£º361008

µç»°£º0592-5908028 ´«Õ棺0592-5908039 ×ÉѯÐÅÏ䣺web@lingzhong.cn ×ÉѯOICQ£º173723134

¡¶ÖлªÈËÃñ¹²ºÍ¹úÔöÖµµçÐÅÒµÎñ¾­ÓªÐí¿ÉÖ¤¡·ÃöB2-20100024  ICP±¸°¸:ÃöICP±¸05037997ºÅ