我有一个关于Session Bean的问题。 EJBLocalHome getEjbLocalHome(beanname)switch beannamecase ... ejbname = ... return ctx.lookup(ejbname) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public EJBLocalHome getLocalHome(String localHome) { EJBLocalHome home = null; Context ctx = new InitialContext(); try { switch(localHome) case .. home = (EJBLocalHome) ctx.lookup(localHome); } catch (Exception e) { e.printStackTrace(); } return home; } 这里的EJBLocalHome 是超类的类型吗?这样,我怎么调用子类里的方法? 把操作封装成Event或是Action,用来区分,然后再分派到不同的Session Bean处理。 首先要感谢 inprise_lyj(只愛一點點) 。到了这一步你还不知道什么用。真不知道ejb你是怎么学的。 你这个方法我早就知道,不过,不是我要的。这样,如果,我增加一个业务逻辑的Bean就意味这,我就要改一下这个方法。我想要的是,dispatcher与后面的业务逻辑的bean无关。可能,我的j2ee学的还不是很好。这个方案,我以前用com+,实现了的。我现在想把这个机构迁移到ejb上。请大家帮忙啊,谢谢 可以在那个组织业务逻辑的EJB中调用资源环境啊,比如<env-entry>、ejb-ref啊! 你不如写个JAVABEAN专门控制你要雕哪个JNDI名和BEAN名呢。 public class ServiceLocator{ private static ServiceLocator serviceLocator = null; private static Hashtable dataSourceCache = null; private static Hashtable ejgHomeCache = null; public static String DATASOURCENAME=JNDINames.DATASOURCENAME; static { serviceLocator = new ServiceLocator(); } private ServiceLocator() { dataSourceCache = new Hashtable(); ejgHomeCache = new Hashtable(); } public static ServiceLocator getInstance() { return serviceLocator; } public Connection getConnection(String jdbcName) throws ServiceLocatorException { Connection conn = null; try { if (dataSourceCache.containsKey(jdbcName)) { DataSource oldDs = (DataSource) dataSourceCache.get(jdbcName); conn= oldDs.getConnection(); return conn; } else { javax.naming.InitialContext ictx = new javax.naming.InitialContext(); DataSource newDs = (DataSource) ictx.lookup(jdbcName); dataSourceCache.put(jdbcName, newDs); conn= newDs.getConnection(); return conn; } } catch (SQLException e1) { throw new ServiceLocatorException("SQL error has occurred in get connection"+e1); } catch (NamingException e2) { throw new ServiceLocatorException(" JDNI naming has occurred" +e2); } catch (Exception e3) { throw new ServiceLocatorException("exception has occurred in get connection"+e3); } } public EJBHome getEJBHome(String jndiName, Class className) throws ServiceLocatorException { EJBHome ejbHome = null; try { if (dataSourceCache.containsKey(jndiName)) { ejbHome = (EJBHome) dataSourceCache.get(jndiName); return ejbHome; } else { javax.naming.InitialContext ictx = new javax.naming.InitialContext(); Object jndiRef = ictx.lookup(jndiName); ejbHome = (EJBHome) PortableRemoteObject.narrow(jndiRef, className); dataSourceCache.put(jndiName, ejbHome); return ejbHome; } } catch (NamingException e2) { throw new ServiceLocatorException(" JDNI naming has occurred" +e2); } catch (Exception e3) { throw new ServiceLocatorException("exception has occurred in get connection"+e3); } }} struts2跳转到另外一个工程里的页面 求教STRTUS2中URL问题 BBS论坛通知问题,请高手给点思路或建议 自己写的连接池,帮忙看看有什么问题。 分不式缓存问题,请给位留步 请问如何在ant中指定程序所需要的文件? SAX解析过程中遇到exception,如何跳过exception使解析过程继续 请问如何下载Spring3.1.1的源码 100分求助,关于struts1.1中的特性是否和jdbc驱动冲突的问题。 Tomcat容器下JSP文件的运行问题(很菜的问题) cmp小问题 你遇到过类似的问题吗?(JBuilder9+Weblogic7)
EJBLocalHome home = null;
Context ctx = new InitialContext();
try {
switch(localHome)
case ..
home = (EJBLocalHome) ctx.lookup(localHome);
}
catch (Exception e) {
e.printStackTrace();
}
return home;
}
这样,我怎么调用子类里的方法?
就意味这,我就要改一下这个方法。我想要的是,dispatcher与后面的业务逻辑的bean无关。
可能,我的j2ee学的还不是很好。这个方案,我以前用com+,实现了的。我现在想把这个机构迁移到ejb上。请大家帮忙啊,谢谢
{ private static ServiceLocator serviceLocator = null;
private static Hashtable dataSourceCache = null;
private static Hashtable ejgHomeCache = null;
public static String DATASOURCENAME=JNDINames.DATASOURCENAME; static
{
serviceLocator = new ServiceLocator();
} private ServiceLocator()
{
dataSourceCache = new Hashtable();
ejgHomeCache = new Hashtable(); } public static ServiceLocator getInstance()
{
return serviceLocator;
} public Connection getConnection(String jdbcName) throws
ServiceLocatorException
{
Connection conn = null; try { if (dataSourceCache.containsKey(jdbcName)) {
DataSource oldDs = (DataSource) dataSourceCache.get(jdbcName);
conn= oldDs.getConnection();
return conn;
}
else {
javax.naming.InitialContext ictx = new javax.naming.InitialContext();
DataSource newDs = (DataSource) ictx.lookup(jdbcName);
dataSourceCache.put(jdbcName, newDs);
conn= newDs.getConnection();
return conn;
}
}
catch (SQLException e1) {
throw new ServiceLocatorException("SQL error has occurred in get connection"+e1);
}
catch (NamingException e2) {
throw new ServiceLocatorException(" JDNI naming has occurred" +e2);
}
catch (Exception e3) {
throw new ServiceLocatorException("exception has occurred in get connection"+e3);
} } public EJBHome getEJBHome(String jndiName, Class className) throws
ServiceLocatorException
{
EJBHome ejbHome = null;
try {
if (dataSourceCache.containsKey(jndiName)) {
ejbHome = (EJBHome) dataSourceCache.get(jndiName);
return ejbHome;
}
else {
javax.naming.InitialContext ictx = new javax.naming.InitialContext();
Object jndiRef = ictx.lookup(jndiName);
ejbHome = (EJBHome) PortableRemoteObject.narrow(jndiRef,
className);
dataSourceCache.put(jndiName, ejbHome);
return ejbHome;
}
}
catch (NamingException e2) {
throw new ServiceLocatorException(" JDNI naming has occurred" +e2);
}
catch (Exception e3) {
throw new ServiceLocatorException("exception has occurred in get connection"+e3);
}
}}