Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to access application level object outside from web container?  RSS feed

 
Joe Blant
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

i try


when i run this servlet in console, got exception at calling to getServletConfig() method,NullPointerException come out.

i would like to access application level outside of web container. Are there any way to instantiate ServletConfig to call web application obj.

Thanks,
Kami Kaze
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Servlets (and their associated ServletConfig and ServletContext objects) only have meaning inside of a servlet container, so what you propose can't work. What are you trying to do?
[ November 02, 2006: Message edited by: Ulf Dittmer ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66188
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Kami Kaze", you have previously been warned on multiple occasions regarding adjusting your display name to meet JavaRanch standards. This is not optional, and this is your final warning. Adjust your display name to comply with the required standards prior to your next post.

Failure to comply will result in the removal of your account.

bear
JavaRanch Sheriff
 
Joe Blant
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Ulf Dittmer ,
thanks for your reply.
my purpose is...

i want to deploy web service which access application level object. I want to access application level object, servlet can access application level object, so i let my class extends servlet. then change my source file to jws file( file.jws) to let AXIS deploy my class as web service. but it fail when i access getServletContext() method outside from container.

Are there any way to access , app object?

thanks,
Joe Blant
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A proper design would be to refactor the application level object to be independent of any environment it may run it. That way you can use it from a servlet, from a WS, from a standalone app and any other environment you can think of. Putting business logic in a servlet (as opposed to instantiating business objects in a servlet) should be avoided.
 
Joe Blant
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Ulf Dittmer,

Thanks for your suggession.

May i express my intension of this attempt...

My web application contains application level class which connects to certain host, make connection as long as application live.

I load this connecting object at application startup using certain loader class ....
<servlet>
..
<load-on-startup>1</load-on-startup>
</servlet>


And my web service want to access that connection, and send some message to the host connected by my application level object.


I would like to get suggestion for this case.

Thanks,
Joe Blant
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to get suggestion for this case.

And I would like to steer you away from this design :-)

Don't implement the WS as servlet, it's simply not going to work. Make the cnt object accessible through some static getter method, so that it works whether the calling code is in a servlet, a WS, or somewhere else.
[ November 06, 2006: Message edited by: Ulf Dittmer ]
 
Joe Blant
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf Dittmer,

Thanks for your wise suggestion. I haven't think of this before. I will try it.

Joe Blant
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!