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 <steven.ya...@springsource.com> wrote:
> 
>> From: Steve Yates <steven.ya...@springsource.com>
>> Subject: Re: How to refer to file?
>> To: "Tomcat Users List" <users@tomcat.apache.org>
>> 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-unsubscr...@tomcat.apache.org
>>> For additional commands, e-mail: users-h...@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-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

Reply via email to