-
FEATURED COMPONENTS
First time here? Check out the FAQ!
How can I call getServletContext in GenericForwardComposer ??
Desktop.getWebApp().getNativeContext()
sorry, this cannot work...
I use under code, but the ide appear "Cannot make a static reference to the non-static method getWebApp() from the type Desktop"
public static SessionFactory getHibernateFactory() { org.zkoss.zk.ui.Desktop.getWebApp().getNativeContext(); return null; }
Please try this
Sessions.getCurrent().getWebApp().getNativeContext();
I think you're still going to have a problem. The fact that your getHibernateFactory() is a static method means that no call to an instance method is allowed. If you *really* need getHibernateFactory() to be static, then you're going to have to get the servlet context before you call that and pass it in. If you don't need it static (and I'm not sure why you would), just remove static. If getHibernateFactory() is in your subclass of GenericForwardComposer, I don't see why it needs to be static.
Hello vdrockywang,
Please try the code below in order to get the deployment path of your application:
System.out.println("\nApp Deployed Directory path: " + Sessions.getCurrent().getWebApp().getServletContext().getRealPath("/"));
System.out.println("getContextPath(): " + Sessions.getCurrent().getWebApp().getServletContext().getContextPath());
System.out.println("Apache Tomcat Server: " + Sessions.getCurrent().getWebApp().getServletContext().getServerInfo());
System.out.println("Servlet API version: " + Sessions.getCurrent().getWebApp().getServletContext().getMajorVersion() + "." +Sessions.getCurrent().getWebApp().getServletContext().getMinorVersion());
System.out.println("Tomcat Project Name: " + Sessions.getCurrent().getWebApp().getServletContext().getServletContextName());
*Dont forget to import the library "import org.zkoss.zk.ui.Sessions";
Best Regards,
Darksu
Asked: 2009-09-24 07:05:57 +0800
Seen: 1,231 times
Last updated: Aug 25 '14