File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object through out application

 
Rudradutt Joshi
Ranch Hand
Posts: 45
Fedora Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Rudradutt Joshi
Ranch Hand
Posts: 45
Fedora Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
Fedora Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 45
Fedora Google Web Toolkit Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic