RE: application.getRealPath() in JSP from a subdirectory
From: Qiao Jin [mailto:bra...@gmail.com] Subject: RE: application.getRealPath() in JSP from a subdirectory Could you elaborate a bit on your statement: Using getRealPath() inside an app server of any kind is pretty much always a Bad Idea? The container (app server) is under no obligation to provide access to the file system, other than the workspace area indicated by the javax.servlet.context.tempdir ServletContext attribute. The container may be running on a platform that does not even have a file system (e.g., a router), some webapps may be deployed only in memory, or the webapp may be deployed via an archive of some sort. While getRealPath() likely will work when you're in complete control of the execution environment, you cannot count on it in general. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: application.getRealPath() in JSP from a subdirectory
Mark, Thanks for your help. This makes sense. I misunderstood the meaning of appBase. getRealPath() is behaving well now, although I will explore the other options Chuck mentioned. Regards, Qiao -Original Message- From: Mark Thomas [mailto:ma...@apache.org] Sent: Friday, January 30, 2009 11:09 PM To: Tomcat Users List Subject: Re: application.getRealPath() in JSP from a subdirectory Qiao Jin wrote: Serving mydomain.com, what I have is one application in an unpacked directory, 'app-root', with jsp files located in the root dir or its subdirs. The Host for mydomain.com has its appBase pointing to 'app-root'. The ROOT.xml for mydomain.com has only one line: Context path= docBase= reloadable=true/ I read the document on the two attributes appBase and docBase, but it is not very clear to me what the difference is. In my case, what should docBase be? The quickest fix will be: - stop Tomcat - delete ROOT.xml - create a new dir called ROOT under app-root - copy the contents of app-root to app-root/ROOT - make sure there is no ROOT.xml in CATALINA_BASE/conf/engine/host - start Tomcat Mark Thanks and regards, Qiao -Original Message- From: Mark Thomas [mailto:ma...@apache.org] Sent: Friday, January 30, 2009 9:23 PM To: Tomcat Users List Subject: Re: application.getRealPath() in JSP from a subdirectory Qiao Jin wrote: Chuck, thanks for your response. It turns out that the auto-deploy switch does affect the situation. New subdirs created after the auto-deploy is turned off are no longer being treated as separate apps and getRealPath is returning the path as I expected. This looks very much like you have configured appBase == docBase for the ROOT web application. This is likely to cause a world of pain - the behaviour you have seen here being just one example. Try restarting Tomcat and see what happens to your getRealPath() calls... docBase should never be set to the same location as appBase. Mark - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: application.getRealPath() in JSP from a subdirectory
From: Qiao Jin [mailto:bra...@gmail.com] Subject: application.getRealPath() in JSP from a subdirectory I am using Tomcat 6.0.18, JDK 1.5 on CentOS 5. From within a JSP page, applicaton.getRealPath() is returning results that I wasn't expecting. Using getRealPath() inside an app server of any kind is pretty much always a Bad Idea. If you need to access a file from your webapp, use ServletContext.getResourceAsStream(). If you need a place to store a file, it certainly shouldn't be inside the webapp deployment area, which should be treated as read-only. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: application.getRealPath() in JSP from a subdirectory
Chuck, thanks for your response. It turns out that the auto-deploy switch does affect the situation. New subdirs created after the auto-deploy is turned off are no longer being treated as separate apps and getRealPath is returning the path as I expected. ServletContext.getResourceAsStream() is fine for accessing a file. In my case, I need to list all the files under an image directory. Here is my directory structure: Approot/sub1/test.jsp Approot/sub1/images/{image files} test.jsp needs to present a list of all images in the sub1 dir, thus it needs a File object representing images. I tried to use ServletContext.getResource(/sub1/images), the resultant URL was converted to an URI with .toURI() and fed to 'new File()'. It didn't work. File(URI) requires an URI with the file scheme. Qiao -Original Message- From: Caldarale, Charles R [mailto:chuck.caldar...@unisys.com] Sent: Friday, January 30, 2009 12:09 PM To: Tomcat Users List Subject: RE: application.getRealPath() in JSP from a subdirectory From: Qiao Jin [mailto:bra...@gmail.com] Subject: application.getRealPath() in JSP from a subdirectory I am using Tomcat 6.0.18, JDK 1.5 on CentOS 5. From within a JSP page, applicaton.getRealPath() is returning results that I wasn't expecting. Using getRealPath() inside an app server of any kind is pretty much always a Bad Idea. If you need to access a file from your webapp, use ServletContext.getResourceAsStream(). If you need a place to store a file, it certainly shouldn't be inside the webapp deployment area, which should be treated as read-only. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: application.getRealPath() in JSP from a subdirectory
Qiao- file:///foo/bar is a URI http://java.sun.com/javase/6/docs/api/java/net/URI.html Martin __ Disclaimer and confidentiality note Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. From: bra...@gmail.com To: users@tomcat.apache.org Subject: RE: application.getRealPath() in JSP from a subdirectory Date: Fri, 30 Jan 2009 18:52:30 -0800 Chuck, thanks for your response. It turns out that the auto-deploy switch does affect the situation. New subdirs created after the auto-deploy is turned off are no longer being treated as separate apps and getRealPath is returning the path as I expected. ServletContext.getResourceAsStream() is fine for accessing a file. In my case, I need to list all the files under an image directory. Here is my directory structure: Approot/sub1/test.jsp Approot/sub1/images/{image files} test.jsp needs to present a list of all images in the sub1 dir, thus it needs a File object representing images. I tried to use ServletContext.getResource(/sub1/images), the resultant URL was converted to an URI with .toURI() and fed to 'new File()'. It didn't work. File(URI) requires an URI with the file scheme. Qiao -Original Message- From: Caldarale, Charles R [mailto:chuck.caldar...@unisys.com] Sent: Friday, January 30, 2009 12:09 PM To: Tomcat Users List Subject: RE: application.getRealPath() in JSP from a subdirectory From: Qiao Jin [mailto:bra...@gmail.com] Subject: application.getRealPath() in JSP from a subdirectory I am using Tomcat 6.0.18, JDK 1.5 on CentOS 5. From within a JSP page, applicaton.getRealPath() is returning results that I wasn't expecting. Using getRealPath() inside an app server of any kind is pretty much always a Bad Idea. If you need to access a file from your webapp, use ServletContext.getResourceAsStream(). If you need a place to store a file, it certainly shouldn't be inside the webapp deployment area, which should be treated as read-only. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org _ HotmailĀ® goes where you go. On a PC, on the Web, on your phone. http://www.windowslive-hotmail.com/learnmore/versatility.aspx#mobile?ocid=TXT_TAGHM_WL_HM_versatility_121208
RE: application.getRealPath() in JSP from a subdirectory
From: Qiao Jin [mailto:bra...@gmail.com] Subject: RE: application.getRealPath() in JSP from a subdirectory In my case, I need to list all the files under an image directory. Perhaps you could use the customized directory listing capability of the DefaultServlet: http://tomcat.apache.org/tomcat-6.0-doc/default-servlet.html#dir You could also use a filter to modify the output of the DefaultServlet directory listing. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: application.getRealPath() in JSP from a subdirectory
Qiao Jin wrote: Chuck, thanks for your response. It turns out that the auto-deploy switch does affect the situation. New subdirs created after the auto-deploy is turned off are no longer being treated as separate apps and getRealPath is returning the path as I expected. This looks very much like you have configured appBase == docBase for the ROOT web application. This is likely to cause a world of pain - the behaviour you have seen here being just one example. Try restarting Tomcat and see what happens to your getRealPath() calls... docBase should never be set to the same location as appBase. Mark ServletContext.getResourceAsStream() is fine for accessing a file. In my case, I need to list all the files under an image directory. Here is my directory structure: Approot/sub1/test.jsp Approot/sub1/images/{image files} test.jsp needs to present a list of all images in the sub1 dir, thus it needs a File object representing images. I tried to use ServletContext.getResource(/sub1/images), the resultant URL was converted to an URI with .toURI() and fed to 'new File()'. It didn't work. File(URI) requires an URI with the file scheme. Qiao -Original Message- From: Caldarale, Charles R [mailto:chuck.caldar...@unisys.com] Sent: Friday, January 30, 2009 12:09 PM To: Tomcat Users List Subject: RE: application.getRealPath() in JSP from a subdirectory From: Qiao Jin [mailto:bra...@gmail.com] Subject: application.getRealPath() in JSP from a subdirectory I am using Tomcat 6.0.18, JDK 1.5 on CentOS 5. From within a JSP page, applicaton.getRealPath() is returning results that I wasn't expecting. Using getRealPath() inside an app server of any kind is pretty much always a Bad Idea. If you need to access a file from your webapp, use ServletContext.getResourceAsStream(). If you need a place to store a file, it certainly shouldn't be inside the webapp deployment area, which should be treated as read-only. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: application.getRealPath() in JSP from a subdirectory
I will look into your suggestion. Could you elaborate a bit on your statement: Using getRealPath() inside an app server of any kind is pretty much always a Bad Idea? Thanks Qiao -Original Message- From: Caldarale, Charles R [mailto:chuck.caldar...@unisys.com] Sent: Friday, January 30, 2009 7:14 PM To: Tomcat Users List Subject: RE: application.getRealPath() in JSP from a subdirectory From: Qiao Jin [mailto:bra...@gmail.com] Subject: RE: application.getRealPath() in JSP from a subdirectory In my case, I need to list all the files under an image directory. Perhaps you could use the customized directory listing capability of the DefaultServlet: http://tomcat.apache.org/tomcat-6.0-doc/default-servlet.html#dir You could also use a filter to modify the output of the DefaultServlet directory listing. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers. - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: application.getRealPath() in JSP from a subdirectory
Serving mydomain.com, what I have is one application in an unpacked directory, 'app-root', with jsp files located in the root dir or its subdirs. The Host for mydomain.com has its appBase pointing to 'app-root'. The ROOT.xml for mydomain.com has only one line: Context path= docBase= reloadable=true/ I read the document on the two attributes appBase and docBase, but it is not very clear to me what the difference is. In my case, what should docBase be? Thanks and regards, Qiao -Original Message- From: Mark Thomas [mailto:ma...@apache.org] Sent: Friday, January 30, 2009 9:23 PM To: Tomcat Users List Subject: Re: application.getRealPath() in JSP from a subdirectory Qiao Jin wrote: Chuck, thanks for your response. It turns out that the auto-deploy switch does affect the situation. New subdirs created after the auto-deploy is turned off are no longer being treated as separate apps and getRealPath is returning the path as I expected. This looks very much like you have configured appBase == docBase for the ROOT web application. This is likely to cause a world of pain - the behaviour you have seen here being just one example. Try restarting Tomcat and see what happens to your getRealPath() calls... docBase should never be set to the same location as appBase. Mark - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: application.getRealPath() in JSP from a subdirectory
Qiao Jin wrote: Serving mydomain.com, what I have is one application in an unpacked directory, 'app-root', with jsp files located in the root dir or its subdirs. The Host for mydomain.com has its appBase pointing to 'app-root'. The ROOT.xml for mydomain.com has only one line: Context path= docBase= reloadable=true/ I read the document on the two attributes appBase and docBase, but it is not very clear to me what the difference is. In my case, what should docBase be? The quickest fix will be: - stop Tomcat - delete ROOT.xml - create a new dir called ROOT under app-root - copy the contents of app-root to app-root/ROOT - make sure there is no ROOT.xml in CATALINA_BASE/conf/engine/host - start Tomcat Mark Thanks and regards, Qiao -Original Message- From: Mark Thomas [mailto:ma...@apache.org] Sent: Friday, January 30, 2009 9:23 PM To: Tomcat Users List Subject: Re: application.getRealPath() in JSP from a subdirectory Qiao Jin wrote: Chuck, thanks for your response. It turns out that the auto-deploy switch does affect the situation. New subdirs created after the auto-deploy is turned off are no longer being treated as separate apps and getRealPath is returning the path as I expected. This looks very much like you have configured appBase == docBase for the ROOT web application. This is likely to cause a world of pain - the behaviour you have seen here being just one example. Try restarting Tomcat and see what happens to your getRealPath() calls... docBase should never be set to the same location as appBase. Mark - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org