Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help with passing context

 
Jamil Zakaria
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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 ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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 ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Could you please provide an example of how to run it through the constructor thanks.
 
Arvind Sampath
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
thanks, the code worked perfectly!!!
 
Arvind Sampath
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats Great!

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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic