WEB开发网
开发学院软件开发Java 利用 WebSphere Application Server Community Ed... 阅读

利用 WebSphere Application Server Community Edition 中现有的 WebSphere Application Server J2EE 资源

 2009-10-23 00:00:00 来源:WEB开发网   
核心提示: 右键单击 Deployment Descriptor: GeronimoWebApp ,并选择 New => Servlet,利用 WebSphere Application Server Community Edition 中现有的 WebSphere Application Serve

右键单击 Deployment Descriptor: GeronimoWebApp ,并选择 New => Servlet。将 Servlet 命名为 TestEJBServlet,然后单击 Next。


图 11. 创建一个新的 Servlet
利用 WebSphere Application Server Community Edition 中现有的 WebSphere Application Server J2EE 资源

对于 Java 包的名称,输入 devworks.example,然后单击 Next。


图 12. 指定包
利用 WebSphere Application Server Community Edition 中现有的 WebSphere Application Server J2EE 资源

取消选中 doPost,然后单击 Finish。


图13. 完成 Servlet
利用 WebSphere Application Server Community Edition 中现有的 WebSphere Application Server J2EE 资源

为 doGet 方法插入下面的代码:

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws 
ServletException, IOException { 
 String text = ""; 
 final String jndiName = "ejb/devworks/example/SimpleEJBHome"; [A] 
 Properties env = new Properties(); 
 env.setProperty(Context.PROVIDER_URL, "iiop://localhost:2809"); [B] 
 env.setProperty(Context.INITIAL_CONTEXT_FACTORY, 
 "com.ibm.websphere.naming.WsnInitialContextFactory"); 
 
 try { 
  
 InitialContext ctx = new InitialContext(env); [C] 
 Object obj = ctx.lookup(jndiName); [D] 
 SimpleEJBHome ejbHome = 
  (SimpleEJBHome) 
  javax.rmi.PortableRemoteObject.narrow(obj, SimpleEJBHome.class); [E] 
 SimpleEJB myEJB = ejbHome.create(); [F] 
  
 text = myEJB.retrieveText(); [G] 
  
 } catch(NamingException ne) { [H] 
 System.err.println("TestEJBServlet failed to lookup SimpleEJBHome. JNDI 
String="+jndiName); 
 ne.printStackTrace(System.err); 
 // Recovery strategy omitted (i.e. try again with a different host/port) 
 } catch(CreateException ce) { 
 System.err.println("TestEJBServlet failed to create SimpleEJB instance."); 
 ce.printStackTrace(System.err); 
 // Recovery strategy omitted (i.e. clear the JNDI resource cache on the 
 // context factory and try again) 
 } 
 response.getWriter().println("Text from WebSphere Server: " + text); [I] 

上一页  4 5 6 7 8 9 10  下一页

Tags:利用 WebSphere Application

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接