RE: getResourceAsStream and relative paths in web.xml
Howdy, *But* this did not work, which I guess is a relative issue: ... public void init(ServletConfig config) throws ServletException { super.init(config); try { this.passwordFile = config.getInitParameter( passwordFile ); this.passwords = new Properties(); passwords.load( new FileInputStream( passwordFile ); } catch( IOException ioe ) {} } ... Can someone summarize why the second example does not work with relative paths? I understand why the first one does. Two reasons, one certain and one possible: 1. Certainly, using a FileXXX class will attempt to interpret the init parameter value (/WEB-INF...) is an absolute path, because that's how absolute paths are defined for files. 2. If you happen to be running from a packed .war file, you may NPE when trying to construct a FileInputStream as File-based accesses are not a given in a packed .war. Yoav Shapira This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: getResourceAsStream and relative paths in web.xml
Howdy, Oh and by the way, it's a good habit to override the init() method for a servlet rather than the init(ServletConfig) one. Simply so you don't accidentally forget to call super(config). Yoav Shapira Millennium ChemInformatics -Original Message- From: Shapira, Yoav Sent: Friday, June 13, 2003 12:42 PM To: Tomcat Users List; [EMAIL PROTECTED] Subject: RE: getResourceAsStream and relative paths in web.xml Howdy, *But* this did not work, which I guess is a relative issue: ... public void init(ServletConfig config) throws ServletException { super.init(config); try { this.passwordFile = config.getInitParameter( passwordFile ); this.passwords = new Properties(); passwords.load( new FileInputStream( passwordFile ); } catch( IOException ioe ) {} } ... Can someone summarize why the second example does not work with relative paths? I understand why the first one does. Two reasons, one certain and one possible: 1. Certainly, using a FileXXX class will attempt to interpret the init parameter value (/WEB-INF...) is an absolute path, because that's how absolute paths are defined for files. 2. If you happen to be running from a packed .war file, you may NPE when trying to construct a FileInputStream as File-based accesses are not a given in a packed .war. Yoav Shapira This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: getResourceAsStream and relative paths in web.xml
1. Certainly, using a FileXXX class will attempt to interpret the init parameter value (/WEB-INF...) is an absolute path, because that's how absolute paths are defined for files. Thank you again Yoav. The recommendation then is to skip trying to use a FileInputStream (because the String provided is absolute to the file system not servlet context, i.e. /WEB-INF/lib/x.props is intepreted as from root on *NIX and C:\ on Windoze). Additionally config.getServletContext().getResourceAsStream( file ) works in and out of war packages. Thank you again, Tim - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: getResourceAsStream and relative paths in web.xml
Howdy, You got it. Yoav Shapira Millennium ChemInformatics -Original Message- From: Timothy Stone [mailto:[EMAIL PROTECTED] Sent: Friday, June 13, 2003 12:56 PM To: Tomcat Users List Subject: Re: getResourceAsStream and relative paths in web.xml 1. Certainly, using a FileXXX class will attempt to interpret the init parameter value (/WEB-INF...) is an absolute path, because that's how absolute paths are defined for files. Thank you again Yoav. The recommendation then is to skip trying to use a FileInputStream (because the String provided is absolute to the file system not servlet context, i.e. /WEB-INF/lib/x.props is intepreted as from root on *NIX and C:\ on Windoze). Additionally config.getServletContext().getResourceAsStream( file ) works in and out of war packages. Thank you again, Tim - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] This e-mail, including any attachments, is a confidential business communication, and may contain information that is confidential, proprietary and/or privileged. This e-mail is intended only for the individual(s) to whom it is addressed, and may not be saved, copied, printed, disclosed or used by anyone else. If you are not the(an) intended recipient, please immediately delete this e-mail from your computer system and notify the sender. Thank you. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]