aspose file tools*
The moose likes Servlets and the fly likes Servlet Filter: how to resolve path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Filter: how to resolve path" Watch "Servlet Filter: how to resolve path" New topic
Author

Servlet Filter: how to resolve path

Max Tomlinson
Ranch Hand

Joined: Jul 17, 2001
Posts: 365
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: 365
That'll do nicely, sir.
Thanks for this very helpful tip.
Max Tomlinson
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Filter: how to resolve path