{"id":66328,"date":"2021-07-18T11:25:00","date_gmt":"2021-07-18T15:25:00","guid":{"rendered":"http:\/\/bangla.salearningschool.com\/recent-posts\/accessing-ejbs-from-servlet-java-short-notes\/"},"modified":"2021-07-18T11:25:00","modified_gmt":"2021-07-18T15:25:00","slug":"accessing-ejbs-from-servlet-java-short-notes","status":"publish","type":"post","link":"http:\/\/bangla.sitestree.com\/?p=66328","title":{"rendered":"Accessing EJBS from Servlet #Java Short Notes"},"content":{"rendered":"<ul>\n<li> EJBs can be used to create enterprise applications like banking systems. Clients will interact with such systems for operations like: withdraw cash, transfer cash, pay bills<\/li>\n<li> When clients directly access EJBs it poses concerns such as: security risks, firewall blocking, EJB architecture becomes transparent to the clients<\/li>\n<li> Servlets can act as the middleman between the EJBs and clients.\n<ul>\n<li> Change to EJB becomes easier &#8211; hidden from the user <\/li>\n<li> Data in EJB better protected <\/li>\n<li> Central control of EJBs <\/li>\n<\/ul>\n<\/li>\n<li> When servlets work as the proxy, smaller devices become capable to access EJBs through http protocol (light weight protocol &#8211; good for smaller devices ) <\/li>\n<li> Servlets can work as a front controller<\/li>\n<li> Supports different types of clients<\/li>\n<li> Better separation of responsibilities that is desirable &#8211; web: flow control logic, EJBs: business logic, EIS: Enterprise Information Systems<\/li>\n<li> Remember: servlets can be bottlenecks here, better servlet design strategy is required &#8211; synchronization may help<\/li>\n<li> For small applications &#8211; may be overkill<\/li>\n<\/ul>\n<p><b>How to use EJBs from servlets<\/b> <\/p>\n<ul>\n<li> Think about a banking system implemented in EJBs. <\/li>\n<li> Entity beans = Customers, Accounts <\/li>\n<li> Session beans = operations like withdraw cash<\/li>\n<li> In this scenario, servlets can call the session beans and return the results to the clients<\/li>\n<li> A sample servlet to access the EJBs: Here remote ejbs are assumed : EJB2 is assumed : just example is shown &#8211; the coding style may not be great &#8230; just an example<\/li>\n<li>\n<pre>\/\/ for remote references to objects such as EJBsimport javax.rmi.PortableRemoteObject;\/\/banking system ejb packageimport bankingSystemEjbClasses.*;import java.io.*;import javax.servlet.*;import javax.servlet.http.*;import javax.naming.*;public class ServletEjb extends HttpServlet{   public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException{  float credit = 10;  float debit = 20;  String custName = \"\";  float initBalance = 0, endBalance = 0;  try{      \/\/locate and instantiate the account manager bean      Context context = new InitialContext();      Object ref = context.lookup(\"AccountManager\");      AccountManagerHome accountManagerHome = (AccountManagerHome) PortableRemoteObject.narrow (ref, AccountManagerHome.class);      AccountManager accountManager  = accountManagerHome.create(); \/\/create a savings account and manipulate itaccountManager.createSavingsAccount(1,\"John Smith\")  initBalance = accountManager.getInitialBalance(\"1\");\/\/create customeraccountManager.createCustomer(1,\"John Smith\")  custName = accountManager.getCustomerName();\/\/generate outputresponse.setContentType(\"text\/html\");PrintWriter out = response.getWriter();out.println(\"\");out.println(\"\");out.println(\"Customer Name:\" + custName);out.println(\"Initial Balance:\" + initBalance);out.println(\"\");out.println(\"\");  }catch(Exception ex){}}}<\/pre>\n<\/li>\n<\/ul>\n<p> From: http:\/\/sitestree.com\/?p=4965<br \/> Categories:Java Short Notes<br \/>Tags:<br \/> Post Data:2010-04-10 03:31:53<\/p>\n<p>\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com\/' target='new' rel=\"noopener\">https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\t(Big Data, Cloud, Security, Machine Learning): Courses: <a href='http:\/\/Training.SitesTree.com' target='new' rel=\"noopener\"> http:\/\/Training.SitesTree.com<\/a><br \/>\n\t\tIn Bengali: <a href='http:\/\/Bangla.SaLearningSchool.com' target='new' rel=\"noopener\">http:\/\/Bangla.SaLearningSchool.com<\/a><br \/>\n\t\t<a href='http:\/\/SitesTree.com' target='new' rel=\"noopener\">http:\/\/SitesTree.com<\/a><br \/>\n\t\t8112223 Canada Inc.\/JustEtc: <a href='http:\/\/JustEtc.net' target='new' rel=\"noopener\">http:\/\/JustEtc.net (Software\/Web\/Mobile\/Big-Data\/Machine Learning) <\/a><br \/>\n\t\tShop Online: <a href='https:\/\/www.ShopForSoul.com'> https:\/\/www.ShopForSoul.com\/<\/a><br \/>\n\t\tMedium: <a href='https:\/\/medium.com\/@SayedAhmedCanada' target='new' rel=\"noopener\"> https:\/\/medium.com\/@SayedAhmedCanada <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>EJBs can be used to create enterprise applications like banking systems. Clients will interact with such systems for operations like: withdraw cash, transfer cash, pay bills When clients directly access EJBs it poses concerns such as: security risks, firewall blocking, EJB architecture becomes transparent to the clients Servlets can act as the middleman between the &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/bangla.sitestree.com\/?p=66328\">Continue reading<\/a><\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1917],"tags":[],"class_list":["post-66328","post","type-post","status-publish","format-standard","hentry","category-fromsitestree-com","item-wrap"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":66421,"url":"http:\/\/bangla.sitestree.com\/?p=66421","url_meta":{"origin":66328,"position":0},"title":"Key J2EE  Components : Basic Concepts with Examples #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 19, 2021","format":false,"excerpt":"Java EE 5 (J2EE 5) uses XML deployment descriptors for the configuration of the web-applications and web-components. What Java EE provides? It provides the internal framework\/structure\/system level capability\/system-level infrastructure to support large enterprise level applications with features like distributed database, distributed computing , security, and transaction management. J2EE also provides\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":66338,"url":"http:\/\/bangla.sitestree.com\/?p=66338","url_meta":{"origin":66328,"position":1},"title":"J2EE Architecture: J2EE Design Patterns: Related Concepts #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 18, 2021","format":false,"excerpt":"Design Patterns What are design patterns? Design patterns are specific\/(context-based) solutions\/approaches to address specific problems\/situations. Some problems are general\/open problems and very common problems in a particular type of applications. Design patterns can be created to solve such problems in a specific context and that can be re-used every time\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":67372,"url":"http:\/\/bangla.sitestree.com\/?p=67372","url_meta":{"origin":66328,"position":2},"title":"Video Tutorials on Different Java technologies #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 20, 2021","format":false,"excerpt":"The following video tutorials contains videos on Basic and Advanced Servlet and JSP Development Understanding and Developing EJBs Portal Development and Administration WebSphere Application Server Administration Struts Development with WSAD 5.1Video Tutorials JSPs with IRAD The HttpSession Creating JavaBeans Testing with JUnit Advanced Web Coding JSPs with jsp:usebean Obtaining User\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":65975,"url":"http:\/\/bangla.sitestree.com\/?p=65975","url_meta":{"origin":66328,"position":3},"title":"Introduction to Spring #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 18, 2021","format":false,"excerpt":"Open-sourced on February, 2003 Layered J2EE application framework Inversion of Control (IoC): A Data Access Object (DAO) depends on a DataSource. Allows: code to interfaces Spring has classes to support Hibernate, Struts, and other frameworks According to many Java developers [ref:internet], J2EE patterns are sometimes cumbersome. Spring uses patterns but\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":66423,"url":"http:\/\/bangla.sitestree.com\/?p=66423","url_meta":{"origin":66328,"position":4},"title":"JSF: Lesson &#8211; 1: JSF Specifications #Java Short Notes","author":"Author-Check- Article-or-Video","date":"July 19, 2021","format":false,"excerpt":"Video Demonstration of a sample JSF application create: Read the article first JSF Specifications JSF is not standalone technology, you have to use it in conjunction with JSPs, Servlets, EJBs How to use JSF with Servlets and EJBs: In Servlet or EJB, explicitly create instances of UI components and use\u2026","rel":"","context":"In &quot;FromSitesTree.com&quot;","block_context":{"text":"FromSitesTree.com","link":"http:\/\/bangla.sitestree.com\/?cat=1917"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":78391,"url":"http:\/\/bangla.sitestree.com\/?p=78391","url_meta":{"origin":66328,"position":5},"title":"Code Refactoring in Java EE","author":"Sayed","date":"August 23, 2025","format":false,"excerpt":"From AI Tools\/OpenAI\/Internet \" Absolutely! Here\u2019s a concise, copyright-free summary of Java EE code refactoring Java EE Code Refactoring: Best Practices Refactoring in Java EE helps improve code quality, maintainability, and performance without changing functionality. Here are some key practices: 1. General Refactoring Remove duplicate code with helper methods or\u2026","rel":"","context":"In &quot;Anything JAVA&quot;","block_context":{"text":"Anything JAVA","link":"http:\/\/bangla.sitestree.com\/?cat=1975"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/66328","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=66328"}],"version-history":[{"count":0,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=\/wp\/v2\/posts\/66328\/revisions"}],"wp:attachment":[{"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=66328"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=66328"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/bangla.sitestree.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=66328"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}