• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

help with passing context

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not looking deep into it yet, but why don't you pass the path (not a pun) to RunClasses' constructor ?
 
Sheriff
Posts: 67597
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jamil Zakaria
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please provide an example of how to run it through the constructor thanks.
 
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks, the code worked perfectly!!!
 
Arvind Sampath
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats Great!

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

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic