Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem calling setAttribute in my Filter init

 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the value of tempMap at the time of the call?
 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Abiodun Adisa
Ranch Hand
Posts: 495
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic