aspose file tools*
The moose likes Servlets and the fly likes Object through out application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Object through out application" Watch "Object through out application" New topic
Author

Object through out application

Rudradutt Joshi
Ranch Hand

Joined: Dec 06, 2008
Posts: 45

Hello there,

I am developing a web application, now what I want to do is to use a HASHMAP through out the application, by mean when server starts to server stops and I should be able to play with it mean while also.

Thanks for your time.

PS : session is not available to me always
[ December 16, 2008: Message edited by: rudradutt joshi ]
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Hi there,

I'm afraid I don't understand your question. Are you saying that you want to be able to control the stopping and starting of the server from your code?


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Rudradutt Joshi
Ranch Hand

Joined: Dec 06, 2008
Posts: 45

NO,
what I want to do is,
create an Object which's scope is application.
I want to create an Object (suppose myObject).
Now when I request for Object say

if it will be null, than I will create value for "keyName" and add it to Object

now I want this Object to be available throughout the application like HttpSession
but I dont have any HTTP request,response to create a session with my current status.

[ December 16, 2008: Message edited by: rudradutt joshi ]
[ December 16, 2008: Message edited by: rudradutt joshi ]
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

Oh, OK, I think I understand now, you're looking to put items into the application scope.

Have you had a look at the ServletContext class?

e.g.:



Also, moving this to Servlet forum.
Rudradutt Joshi
Ranch Hand

Joined: Dec 06, 2008
Posts: 45

so what I tried is


which will be loaded on start up

now how will I found the servletContext from another bean like


[ December 17, 2008: Message edited by: rudradutt joshi ]
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458

That said, it doesn't necessarily have to be a servlet. That's a very odd design. Just let an HttpServlet (or, better, a ServletContextListener) create an independent FenceMap object and place it in the desired scope.

Also, testing servlets as a Java Application (with main()) isn't going to work. Test it as a servlet in a real webcontainer. Use an appserver and a webbrowser or JUnit.
[ December 17, 2008: Message edited by: Bauke Scholtz ]
Rudradutt Joshi
Ranch Hand

Joined: Dec 06, 2008
Posts: 45

Thank you, for your help.

I had redesign the ServletContextListener for the application, but now as it is happening, I have to accept some times request from TCP/UDP ports also.
In such cases it throws
java.lang.NullPointerException

as no servletcontext is available.

So i want a solution of that.

regards,
Rudradutt
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Originally posted by rudradutt joshi:
In such cases it throws

as no servletcontext is available.

So i want a solution of that.

Did you read my last comment anyway?

Also, testing servlets as a Java Application (with main()) isn't going to work. Test it as a servlet in a real webcontainer. Use an appserver and a webbrowser or JUnit.

You need to test it in a webcontainer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object through out application