You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Sasikumar Muralikrishnan <sa...@pointelsolutions.com> on 2015/02/10 13:14:48 UTC

Reg. getRealPath("/") _ How does the result of this method differ in Tomcat 7 and Tomcat 8

Hi Team,

Using this method

getServletContext().getRealPath("/")

returns '\' at the end when I run my project in Tomcat 7 whereas it is not
working as such in Tomcat 8.

For example,
In Tomcat 7 it returns as "D:\Tomcat\webapps\project\"
In Tomcat 8 it returns as "D:\Tomcat\webapps\project"

At present the project is in production so, I am unable to change the code
in every part(where i use getRealPath("/")). Is there a way/setting in
tomcat level configuration to make it resolved.

Additional information,
	
Tomcat version : 8.0.14

OS : Windows server 2008 R2 standard

System Type: 64 bit operating system

Thanks,
Sasi Kumar M.



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Reg. getRealPath("/") _ How does the result of this method differ in Tomcat 7 and Tomcat 8

Posted by Sasikumar Muralikrishnan <sa...@pointelsolutions.com>.
Thanks for your thoughts David

-----Original Message-----
From: David kerber [mailto:dckerber@verizon.net] 
Sent: Tuesday, February 10, 2015 3:30 PM
To: Tomcat Users List
Subject: Re: Reg. getRealPath("/") _ How does the result of this method
differ in Tomcat 7 and Tomcat 8

On 2/10/2015 9:14 AM, Sasikumar Muralikrishnan wrote:
> Hi André Warnie,
>
> Great thanks for your response.
>
> But here, I am not writing anything inside the web application.
>
> 1. I have a flat file in the web application and it has some
configurations
> details, which I use for the project.
> 2. Therefore, we are trying to read the configuration detail from that
file.
> 3. And as I mentioned earlier it works fine until tomcat 7. Now, we are
> planning to upgrade to tomcat 8.0.14 and facing this issue.
>
> Please let me know about your valuable thoughts/suggestions.

It looks to me like you're not going to be able to do this without some 
code changes (or just stay in TC 7 for now).  Either check for the 
existence (or not) of the trailing "\" and fix the path string 
accordingly, or since the file you're trying to read is inside your 
context, build the name from the context path rather than the real path. 
  Either way needs code changes, but the second one is more portable 
than the first option.


>
> Thanks,	
> Sasi Kumar M.
>
>
> -----Original Message-----
> From: André Warnier [mailto:aw@ice-sa.com]
> Sent: Tuesday, February 10, 2015 2:29 PM
> To: Tomcat Users List
> Subject: Re: Reg. getRealPath("/") _ How does the result of this method
> differ in Tomcat 7 and Tomcat 8
>
> Sasikumar Muralikrishnan wrote:
>> Hi Team,
>>
>> Using this method
>>
>> getServletContext().getRealPath("/")
>>
>> returns '\' at the end when I run my project in Tomcat 7 whereas it is
not
>> working as such in Tomcat 8.
>>
>> For example,
>> In Tomcat 7 it returns as "D:\Tomcat\webapps\project\"
>> In Tomcat 8 it returns as "D:\Tomcat\webapps\project"
>>
>> At present the project is in production so, I am unable to change the
code
>> in every part(where i use getRealPath("/")). Is there a way/setting in
>> tomcat level configuration to make it resolved.
>>
>> Additional information,
>> 	
>> Tomcat version : 8.0.14
>>
>> OS : Windows server 2008 R2 standard
>>
>> System Type: 64 bit operating system
>>
>> Thanks,
>> Sasi Kumar M.
>>
> Hi.
> I do not know the answer to your question.
> But maybe now would be a good time to examine why you are using
> getServletContext().getRealPath(), and to browse the following thread for
> some good
> reasons not to be doing that.
> http://tomcat.markmail.org/thread/5vfsnf56w2r5gz6q
>
>
>
> ---------------------------------------------------------------------
> 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
>
>


---------------------------------------------------------------------
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


RE: Reg. getRealPath("/") _ How does the result of this method differ in Tomcat 7 and Tomcat 8

Posted by Sasikumar Muralikrishnan <sa...@pointelsolutions.com>.
Hi all,

Thanks for all your response for my question.

Here is something I got finally

https://bz.apache.org/bugzilla/show_bug.cgi?id=57556

Thanks,
Sasi Kumar M.

-----Original Message-----
From: Sasikumar Muralikrishnan [mailto:sasikumar@pointelsolutions.com] 
Sent: Tuesday, February 10, 2015 4:19 PM
To: 'Tomcat Users List'; 'dckerber@verizon.net'
Subject: RE: Reg. getRealPath("/") _ How does the result of this method
differ in Tomcat 7 and Tomcat 8

Thanks for your thoughts David

-----Original Message-----
From: David kerber [mailto:dckerber@verizon.net] 
Sent: Tuesday, February 10, 2015 3:30 PM
To: Tomcat Users List
Subject: Re: Reg. getRealPath("/") _ How does the result of this method
differ in Tomcat 7 and Tomcat 8

On 2/10/2015 9:14 AM, Sasikumar Muralikrishnan wrote:
> Hi André Warnie,
>
> Great thanks for your response.
>
> But here, I am not writing anything inside the web application.
>
> 1. I have a flat file in the web application and it has some
configurations
> details, which I use for the project.
> 2. Therefore, we are trying to read the configuration detail from that
file.
> 3. And as I mentioned earlier it works fine until tomcat 7. Now, we are
> planning to upgrade to tomcat 8.0.14 and facing this issue.
>
> Please let me know about your valuable thoughts/suggestions.

It looks to me like you're not going to be able to do this without some 
code changes (or just stay in TC 7 for now).  Either check for the 
existence (or not) of the trailing "\" and fix the path string 
accordingly, or since the file you're trying to read is inside your 
context, build the name from the context path rather than the real path. 
  Either way needs code changes, but the second one is more portable 
than the first option.


>
> Thanks,	
> Sasi Kumar M.
>
>
> -----Original Message-----
> From: André Warnier [mailto:aw@ice-sa.com]
> Sent: Tuesday, February 10, 2015 2:29 PM
> To: Tomcat Users List
> Subject: Re: Reg. getRealPath("/") _ How does the result of this method
> differ in Tomcat 7 and Tomcat 8
>
> Sasikumar Muralikrishnan wrote:
>> Hi Team,
>>
>> Using this method
>>
>> getServletContext().getRealPath("/")
>>
>> returns '\' at the end when I run my project in Tomcat 7 whereas it is
not
>> working as such in Tomcat 8.
>>
>> For example,
>> In Tomcat 7 it returns as "D:\Tomcat\webapps\project\"
>> In Tomcat 8 it returns as "D:\Tomcat\webapps\project"
>>
>> At present the project is in production so, I am unable to change the
code
>> in every part(where i use getRealPath("/")). Is there a way/setting in
>> tomcat level configuration to make it resolved.
>>
>> Additional information,
>> 	
>> Tomcat version : 8.0.14
>>
>> OS : Windows server 2008 R2 standard
>>
>> System Type: 64 bit operating system
>>
>> Thanks,
>> Sasi Kumar M.
>>
> Hi.
> I do not know the answer to your question.
> But maybe now would be a good time to examine why you are using
> getServletContext().getRealPath(), and to browse the following thread for
> some good
> reasons not to be doing that.
> http://tomcat.markmail.org/thread/5vfsnf56w2r5gz6q
>
>
>
> ---------------------------------------------------------------------
> 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
>
>


---------------------------------------------------------------------
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


Re: Reg. getRealPath("/") _ How does the result of this method differ in Tomcat 7 and Tomcat 8

Posted by David kerber <dc...@verizon.net>.
On 2/10/2015 9:14 AM, Sasikumar Muralikrishnan wrote:
> Hi André Warnie,
>
> Great thanks for your response.
>
> But here, I am not writing anything inside the web application.
>
> 1. I have a flat file in the web application and it has some configurations
> details, which I use for the project.
> 2. Therefore, we are trying to read the configuration detail from that file.
> 3. And as I mentioned earlier it works fine until tomcat 7. Now, we are
> planning to upgrade to tomcat 8.0.14 and facing this issue.
>
> Please let me know about your valuable thoughts/suggestions.

It looks to me like you're not going to be able to do this without some 
code changes (or just stay in TC 7 for now).  Either check for the 
existence (or not) of the trailing "\" and fix the path string 
accordingly, or since the file you're trying to read is inside your 
context, build the name from the context path rather than the real path. 
  Either way needs code changes, but the second one is more portable 
than the first option.


>
> Thanks,	
> Sasi Kumar M.
>
>
> -----Original Message-----
> From: André Warnier [mailto:aw@ice-sa.com]
> Sent: Tuesday, February 10, 2015 2:29 PM
> To: Tomcat Users List
> Subject: Re: Reg. getRealPath("/") _ How does the result of this method
> differ in Tomcat 7 and Tomcat 8
>
> Sasikumar Muralikrishnan wrote:
>> Hi Team,
>>
>> Using this method
>>
>> getServletContext().getRealPath("/")
>>
>> returns '\' at the end when I run my project in Tomcat 7 whereas it is not
>> working as such in Tomcat 8.
>>
>> For example,
>> In Tomcat 7 it returns as "D:\Tomcat\webapps\project\"
>> In Tomcat 8 it returns as "D:\Tomcat\webapps\project"
>>
>> At present the project is in production so, I am unable to change the code
>> in every part(where i use getRealPath("/")). Is there a way/setting in
>> tomcat level configuration to make it resolved.
>>
>> Additional information,
>> 	
>> Tomcat version : 8.0.14
>>
>> OS : Windows server 2008 R2 standard
>>
>> System Type: 64 bit operating system
>>
>> Thanks,
>> Sasi Kumar M.
>>
> Hi.
> I do not know the answer to your question.
> But maybe now would be a good time to examine why you are using
> getServletContext().getRealPath(), and to browse the following thread for
> some good
> reasons not to be doing that.
> http://tomcat.markmail.org/thread/5vfsnf56w2r5gz6q
>
>
>
> ---------------------------------------------------------------------
> 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
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Reg. getRealPath("/") _ How does the result of this method differ in Tomcat 7 and Tomcat 8

Posted by Konstantin Kolinko <kn...@gmail.com>.
2015-02-10 17:14 GMT+03:00 Sasikumar Muralikrishnan
<sa...@pointelsolutions.com>:
> Hi André Warnie,
>
> Great thanks for your response.
>
> But here, I am not writing anything inside the web application.
>
> 1. I have a flat file in the web application and it has some configurations
> details, which I use for the project.
> 2. Therefore, we are trying to read the configuration detail from that file.

1. Do you really need a file?
ServletContext.getResourceAsStream() provides an InputStream
ServletContext.getResource() provides an URL

Both work even if unpackWARs=false.

2. java.io.File  can perform path arithmetics regardless of
terminating '/' in parent path,

new File(parent, child)

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Reg. getRealPath("/") _ How does the result of this method differ in Tomcat 7 and Tomcat 8

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Sasikumar Muralikrishnan [mailto:sasikumar@pointelsolutions.com] 
> Subject: RE: Reg. getRealPath("/") _ How does the result of this method differ in Tomcat 7 and Tomcat 8

> But here, I am not writing anything inside the web application.

> 1. I have a flat file in the web application and it has some configurations
> details, which I use for the project.
> 2. Therefore, we are trying to read the configuration detail from that file.
> 3. And as I mentioned earlier it works fine until tomcat 7. Now, we are
> planning to upgrade to tomcat 8.0.14 and facing this issue.

Any application depending on getRealPath() is inherently flawed.  There is no guarantee in the servlet spec that getRealPath() will ever return anything other than null, since there's no guarantee that deployment occurs within the file system.  It's unfortunate that this interface still exists; it should have been deprecated long ago.

The proper way to read data packaged within the webapp is to use ServletContext.getResourceAsStream(), which is required to work regardless of the packaging and deployment.

 - 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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Reg. getRealPath("/") _ How does the result of this method differ in Tomcat 7 and Tomcat 8

Posted by Sasikumar Muralikrishnan <sa...@pointelsolutions.com>.
Hi André Warnie,

Great thanks for your response.

But here, I am not writing anything inside the web application.

1. I have a flat file in the web application and it has some configurations
details, which I use for the project.
2. Therefore, we are trying to read the configuration detail from that file.
3. And as I mentioned earlier it works fine until tomcat 7. Now, we are
planning to upgrade to tomcat 8.0.14 and facing this issue.

Please let me know about your valuable thoughts/suggestions.

Thanks,	
Sasi Kumar M.


-----Original Message-----
From: André Warnier [mailto:aw@ice-sa.com] 
Sent: Tuesday, February 10, 2015 2:29 PM
To: Tomcat Users List
Subject: Re: Reg. getRealPath("/") _ How does the result of this method
differ in Tomcat 7 and Tomcat 8

Sasikumar Muralikrishnan wrote:
> Hi Team,
> 
> Using this method
> 
> getServletContext().getRealPath("/")
> 
> returns '\' at the end when I run my project in Tomcat 7 whereas it is not
> working as such in Tomcat 8.
> 
> For example,
> In Tomcat 7 it returns as "D:\Tomcat\webapps\project\"
> In Tomcat 8 it returns as "D:\Tomcat\webapps\project"
> 
> At present the project is in production so, I am unable to change the code
> in every part(where i use getRealPath("/")). Is there a way/setting in
> tomcat level configuration to make it resolved.
> 
> Additional information,
> 	
> Tomcat version : 8.0.14
> 
> OS : Windows server 2008 R2 standard
> 
> System Type: 64 bit operating system
> 
> Thanks,
> Sasi Kumar M.
> 
Hi.
I do not know the answer to your question.
But maybe now would be a good time to examine why you are using 
getServletContext().getRealPath(), and to browse the following thread for
some good 
reasons not to be doing that.
http://tomcat.markmail.org/thread/5vfsnf56w2r5gz6q



---------------------------------------------------------------------
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


Re: Reg. getRealPath("/") _ How does the result of this method differ in Tomcat 7 and Tomcat 8

Posted by André Warnier <aw...@ice-sa.com>.
Sasikumar Muralikrishnan wrote:
> Hi Team,
> 
> Using this method
> 
> getServletContext().getRealPath("/")
> 
> returns '\' at the end when I run my project in Tomcat 7 whereas it is not
> working as such in Tomcat 8.
> 
> For example,
> In Tomcat 7 it returns as "D:\Tomcat\webapps\project\"
> In Tomcat 8 it returns as "D:\Tomcat\webapps\project"
> 
> At present the project is in production so, I am unable to change the code
> in every part(where i use getRealPath("/")). Is there a way/setting in
> tomcat level configuration to make it resolved.
> 
> Additional information,
> 	
> Tomcat version : 8.0.14
> 
> OS : Windows server 2008 R2 standard
> 
> System Type: 64 bit operating system
> 
> Thanks,
> Sasi Kumar M.
> 
Hi.
I do not know the answer to your question.
But maybe now would be a good time to examine why you are using 
getServletContext().getRealPath(), and to browse the following thread for some good 
reasons not to be doing that.
http://tomcat.markmail.org/thread/5vfsnf56w2r5gz6q



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org