【发布时间】:2011-01-09 12:03:48
【问题描述】:
嗨,
我使用@WebListener 类在应用程序部署时启动 RMI 连接。这将我的 JSF 前端与后端连接起来。
效果很好!
接下来我想将连接交给 ManagedBean,因为我想使用连接到例如从 bean 中保存一些内容,因为无法从 xhtml 页面访问 weblistener。
我尝试将 managedProperty 放入该类,但我认为这是不允许的。那么该怎么做呢?
@WebListener
public class Config implements ServletContextListener {
public static final String SERVER_NAMING = "xxx";
public static final String SERVER_HOST = "xxx";
public static FrontendCommInterface server;
public void contextInitialized(ServletContextEvent event) {
try {
server = (FrontendCommInterface) Naming.lookup("rmi://" + SERVER_HOST + "/" + SERVER_NAMING);
System.out.println("Connection successfull!");
//HERE THE SERVER SHOULD HANDED TO ANOTHER MANAGEDBEAN !!! BUT HOW TO DO THAT???
} catch (MalformedURLException e) {
System.out.print("Error: " + e.getLocalizedMessage());
} catch (RemoteException e) {
System.out.print("Error: " + e.getLocalizedMessage());
} catch (NotBoundException e) {
System.out.print("Error: " + e.getLocalizedMessage());
}
}
public void contextDestroyed(ServletContextEvent event) {
// Do stuff during webapp's shutdown.
}
【问题讨论】: