0

How to getServletContext in GenericForwardComposer

asked 2009-09-24 07:05:57 +0800

vdrockywang gravatar image vdrockywang
120 2 4

How can I call getServletContext in GenericForwardComposer ??

delete flag offensive retag edit

5 Replies

Sort by ยป oldest newest

answered 2009-09-24 14:25:52 +0800

YamilBracho gravatar image YamilBracho
1722 2

Desktop.getWebApp().getNativeContext()

link publish delete flag offensive edit

answered 2009-09-25 03:04:43 +0800

vdrockywang gravatar image vdrockywang
120 2 4

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;
	}

link publish delete flag offensive edit

answered 2009-09-25 10:43:41 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

Please try this

Sessions.getCurrent().getWebApp().getNativeContext();

link publish delete flag offensive edit

answered 2009-09-25 15:09:15 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

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.

link publish delete flag offensive edit

answered 2014-08-25 08:47:10 +0800

Darksu gravatar image Darksu
1991 1 4

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

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-09-24 07:05:57 +0800

Seen: 1,231 times

Last updated: Aug 25 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More