Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 44559 invoked from network); 18 May 2009 15:25:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 May 2009 15:25:34 -0000 Received: (qmail 22609 invoked by uid 500); 18 May 2009 15:25:30 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 22525 invoked by uid 500); 18 May 2009 15:25:30 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 22513 invoked by uid 99); 18 May 2009 15:25:30 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 May 2009 15:25:30 +0000 X-ASF-Spam-Status: No, hits=1.2 required=10.0 tests=SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [195.156.147.13] (HELO jenni2.inet.fi) (195.156.147.13) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 18 May 2009 15:25:19 +0000 Received: from ichaos.ichaos-int (88.195.115.158) by jenni2.inet.fi (8.5.014) id 49F5CB6400D1BFCD for users@tomcat.apache.org; Mon, 18 May 2009 18:24:59 +0300 Received: from [127.0.0.1] (chaos.ichaos-int [192.168.105.33]) by ichaos.ichaos-int (Postfix) with ESMTP id 0E32D5619 for ; Mon, 18 May 2009 18:24:59 +0300 (EEST) Message-ID: <4A117DCB.6040400@iki.fi> Date: Mon, 18 May 2009 18:24:59 +0300 From: Juha Laiho User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.19) Gecko/20081209 Thunderbird/2.0.0.19 Mnenhy/0.7.6.666 MIME-Version: 1.0 To: Tomcat Users List Subject: Re: How to refer to file? References: <243101.56006.qm@web58302.mail.re3.yahoo.com> In-Reply-To: <243101.56006.qm@web58302.mail.re3.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 090517-0, 17.05.2009), Outbound message X-Antivirus-Status: Clean X-Virus-Checked: Checked by ClamAV on apache.org Hello, by that logic, when you edit a file with Word, the default save location should be the directory where the Word binary is located. The "current directory" with servlet applications is rather weakly defined - and for very strict adherence to servlet specification you shouldn't even expect that the jsp files are located in a directory; the application could be executing from an unexploded .war file without any application-specific directory on the file system. If you only need to read from the file, it would be preferred to use ServlerContext.getResourceAsStream() instead. For read/write access the servlet applications only guarantee an existence of a temporary directory for the application; by breaking the pure servlet application model, you can of course write/read a file to whichever place you see fit (but don't expect any specific default directory; instead use an explicit directory name whenever opening a file. Even if your own code sets the default directory at some point, it's completely possible that some other code in the same process (3rd party library, servlet engine itself, whatever..) can change the default directory without giving any notice. -- ..Juha Dola Woolfe wrote: > Thanks, > But why would a <%! %> tag make a file default to the same dir as the .jsp file. > > When I do > <%! String content = new java.io.File("Hi.txt").getAbsolutePath(); %>, > > I get: > > C:\dc\tomcat\bin\Hi.txt > > > > --- On Mon, 5/18/09, Steve Yates wrote: > >> From: Steve Yates >> Subject: Re: How to refer to file? >> To: "Tomcat Users List" >> Date: Monday, May 18, 2009, 1:28 AM >> Dola Woolfe wrote: >>> Hi, >>> >>> Within a .jsp document, is there a way of referring to >> a file in same directory? >>> For example, new java.io.File(ThisDir, >> "FileName.txt"). >>> Thanks, >>> >>> Dola >>> >>> >>> >>> >>> >> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org >>> For additional commands, e-mail: users-help@tomcat.apache.org >>> >>> >> Hi Dola, >> >> Is this something you really need to do in the view layer >> like this? I >> am going to assume you have a really good reason to do this >> and say that >> it is possible using the same approach as you would declare >> a method in >> a .JSP file. >> >> This is slightly different to the scriptlet approach <% >> %> <%= %> etc >> >> You simply add a ! like so; >> >> <%! >> *File myFile = new >> java.io.File(....);* >> >> public String methodDeclaration(.....) >> { >> //DoSomething >> //... >> return >> StringUtils.EmptyString(); >> } >> %> >> >> Don't forget to include the appropriate package as an >> "import" statement. >> >> RGS SY >> >> >> > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org > For additional commands, e-mail: users-help@tomcat.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org