aspose file tools*
The moose likes Servlets and the fly likes help with passing context Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "help with passing context" Watch "help with passing context" New topic
Author

help with passing context

Jamil Zakaria
Greenhorn

Joined: Jul 20, 2006
Posts: 7
hi,

basically I a sevlet context listener which i use to runs non servlet classes at a particular time. the code is as follows


however when I run these classes (that by the way create text files that need saving on the server hence the need for context path) I want to be able to pass a string with the context path to this classes.

I know I can place the following in contextinitialized to get context,

ServletContext context = getServletContext();
String path2 = context.getRealPath("/")+"Grouped-URL-Files";

I then want to pass the string to the run() method which inturn is passed to each class executed.

However I have not been able to do that yet I tried various things however I keep getting compling problems relating to static and non static and/or null values for the string.

Can anyone tell me how to do it, is it actually possible or is there another way to tell the classes the context path?

Please help

thanks in advance

[ August 09, 2006: Message edited by: Bear Bibeault ]
[ August 10, 2006: Message edited by: Jamil Zakaria ]
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

I'm not looking deep into it yet, but why don't you pass the path (not a pun) to RunClasses' constructor ?


[My Blog]
All roads lead to JavaRanch
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60045
    
  65

If you are going to post more than single line of code, please us the UBB code tags to preserve the formatting.

Please read this.

You can go back and edit your post to fix the code formatting.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jamil Zakaria
Greenhorn

Joined: Jul 20, 2006
Posts: 7
Could you please provide an example of how to run it through the constructor thanks.
Arvind Sampath
Ranch Hand

Joined: May 11, 2005
Posts: 144
As Satou said, you can pass the required info in the constructor. RunClasses will now have a private instance variable for storing the path info.




Pass the desired path in the servlet context listener like this



Hope it helps.
Jamil Zakaria
Greenhorn

Joined: Jul 20, 2006
Posts: 7
thanks, the code worked perfectly!!!
Arvind Sampath
Ranch Hand

Joined: May 11, 2005
Posts: 144
Thats Great!

Oops... I forgot to pass the path here to the constructor

 
jQuery in Action, 2nd edition
 
subject: help with passing context
 
Similar Threads
database connection help
listener tag is not working in Tomcat
ServletContextListener not working
Problem using Tomcat's crossContext
servletcontextlistener