| Author |
Servlet Filter: how to resolve path
|
Max Tomlinson
Ranch Hand
Joined: Jul 17, 2001
Posts: 364
|
|
Hi- I'm writing a couple of filters that our apps will use. I want each app to provide for its own config.fil under /web-inf/. My filters will be deployed as a jar on WAS. In my doFilter method I want to resolve the path to the comfig file e.g. (in doFilter) String cfgFilepath = httpReq.getServerName() +httpReq.getServerPort() +httpReq.getContextPath() +"/WEB-INF/redirect-config.xml"; Parser p = new Parser(); //a SAX parser p.processFile(cfgFilepath); p.listData(); I'm not getting close to my file. Anyone know a way to do this? many thanks, max
|
 |
Steve Leach
Ranch Hand
Joined: Sep 24, 2003
Posts: 46
|
|
|
Could you use FilterConfig.getServletContext().getRealPath(fileName) ?
|
 |
Steve Leach
Ranch Hand
Joined: Sep 24, 2003
Posts: 46
|
|
More specifically... where configFile is a String field of the class.
|
 |
James Carman
Ranch Hand
Joined: Feb 20, 2001
Posts: 580
|
|
|
Why do you care what the "real" path is? Why not use ServletContext.getResource() which returns a URL object representing a resource relative to the document root (which never changes for your webapp). That should get the job done.
|
James Carman, President<br />Carman Consulting, Inc.
|
 |
Max Tomlinson
Ranch Hand
Joined: Jul 17, 2001
Posts: 364
|
|
That'll do nicely, sir. Thanks for this very helpful tip. Max Tomlinson
|
 |
 |
|
|
subject: Servlet Filter: how to resolve path
|
|
|