File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using servlets params from filters

 
Matteo Di Furia
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers, I got a question for you.
in web.xml config file I configured a set of servlets with an init-param (let's call it OP_CODE). Each servlet has its own OP_CODE. Now, since the logic that handles this param is the same for each servlets, I'd like to move this logic to a filter. What I need to know is : is there a way to retrieve the configured value of the OP_CODE param from the filter code, starting from the requested URL ?
I'll try to be a bit more clear:

in web.xml :



Now in filter's code :



I hope I've been clear enough. Any suggestion ?
 
Alan Mehio
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
see this http://www.coderanch.com/t/366066/Servlets/java/get-ServletConfig-reference-filter

You may need to put your param in the request or response. Or you may build an xml or property file and read it when the web application starts through ContextListener then put it into ServletContext. The map contains the Servlet name as key and the OP_CODE as the value.


You can get the ServletContext through the FilterConfig


Regards,
Alan Mehio
London,UK

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Move the value to a context parameter.
 
Matteo Di Furia
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can you move the value as a context parameter when there are more than just one value ?

Mine was just an example, but the real case is like this :



So, there can be n servlets, each with its own OP_CODE param. The check on the OP_CODE value is the same for every servlet, that's why I'm using a filter (by now I pass the OP_CODE value as a request variable, but it's kinda dirty in my opinion). I'm also thinking to remove the filter and let all my servlets to extend an unique one which will do the same logic in her service method. (although I kinda liked the idea of a filter).
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic