File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Problem calling setAttribute in my Filter init Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem calling setAttribute in my Filter init" Watch "Problem calling setAttribute in my Filter init" New topic
Author

Problem calling setAttribute in my Filter init

Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
I have this code in my init method that attempts to set attribute in the servletContext



But anytime i run the application the Filter returns an error anytime it reaches the setAttribute




Any suggestions would be welcome
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61201
    
  66

What is the value of tempMap at the time of the call?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
value of tempMap is some values it retrieves from the database, I was able to resolve this by getting the ServletContext using the ServletRe
Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
Originally posted by Abiodun Adisa:
value of tempMap is some values it retrieves from the database, I was able to resolve this by getting the ServletContext using the ServletRe


value of tempMap is some values it retrieves from the database, I was able to resolve this by getting the ServletContext using the ServletRequest of the filter

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41823
    
  63
The difference is of course that now you're doing this every time the filter is called, instead of once at filter startup. Is that what you want/need to do?

You can get an instance of ServletContext by calling getServletContext() on the FilterConfig object that's passed to the init method.


Ping & DNS - my free Android networking tools app
Abiodun Adisa
Ranch Hand

Joined: Jan 17, 2002
Posts: 495
Originally posted by Ulf Dittmer:
The difference is of course that now you're doing this every time the filter is called, instead of once at filter startup. Is that what you want/need to do?

You can get an instance of ServletContext by calling getServletContext() on the FilterConfig object that's passed to the init method.


Thanks for your reply, I think i would want to do this once, please how do i obtain the ServletContext in the init method
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61201
    
  66

Originally posted by Abiodun Adisa:
Thanks for your reply, I think i would want to do this once, please how do i obtain the ServletContext in the init method
He already told you in the 2nd paragraph.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Problem calling setAttribute in my Filter init