RE: Can servlet write to file in /WEB-INF?

2002-06-24 Thread tamir

Hi,
Making URLConnection to a directory under WEB-INF, is the same like writing
this url in the explorer.
However, You can't go directly to any directory under WEB-INF in that way,
which justifies your failure of
writing to this directory.

You can write to files in this directory, if you don't use URLConnection.
That's what I think
Tamir

-Original Message-
From: john-paul delaney [mailto:[EMAIL PROTECTED]]
Sent: Saturday, June 22, 2002 10:48 AM
To: TC user list
Subject: Can servlet write to file in /WEB-INF?


I was trying to see if I could write to a file in the /WEB-INF directory but
I couldn't get it to work - is there a problem with a servlet writing to
this directory or is it just me (again ;( ) ?

thanks
/j-p.

URL url = context.getResource(/contextTest.txt);
URLConnection con = url.openConnection();
con.setDoOutput(true);
OutputStream out = con.getOutputStream();
PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
pw.println(foo);
pw.close();
out.close();



---
 JUSTATEST Art Online
  www.justatest.com




--
To unsubscribe, e-mail:
mailto:[EMAIL PROTECTED]
For additional commands, e-mail:
mailto:[EMAIL PROTECTED]

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




RE: Can servlet write to file in /WEB-INF?

2002-06-24 Thread andre . powroznik

Instead there is a method in the servlet context : getRealPath(String 
relativefilename) - then you can open a normal fileoutputstream.

-Original Message-
From: tamir [mailto:[EMAIL PROTECTED]]
Sent: 24 June 2002 11:31
To: 'Tomcat Users List'
Subject: RE: Can servlet write to file in /WEB-INF?


Hi,
Making URLConnection to a directory under WEB-INF, is the same like writing
this url in the explorer.
However, You can't go directly to any directory under WEB-INF in that way,
which justifies your failure of
writing to this directory.

You can write to files in this directory, if you don't use URLConnection.
That's what I think
Tamir

-Original Message-
From: john-paul delaney [mailto:[EMAIL PROTECTED]]
Sent: Saturday, June 22, 2002 10:48 AM
To: TC user list
Subject: Can servlet write to file in /WEB-INF?


I was trying to see if I could write to a file in the /WEB-INF directory but
I couldn't get it to work - is there a problem with a servlet writing to
this directory or is it just me (again ;( ) ?

thanks
/j-p.

URL url = context.getResource(/contextTest.txt);
URLConnection con = url.openConnection();
con.setDoOutput(true);
OutputStream out = con.getOutputStream();
PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
pw.println(foo);
pw.close();
out.close();



---
 JUSTATEST Art Online
  www.justatest.com




--
To unsubscribe, e-mail:
mailto:[EMAIL PROTECTED]
For additional commands, e-mail:
mailto:[EMAIL PROTECTED]

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]

 DISCLAIMER  
This e-mail and any attachments thereto may contain information 
which is confidential and/or protected by intellectual property 
rights and are intended for the sole use of the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, 
total or partial reproduction, communication or distribution in any form) 
by persons other than the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either 
by telephone or by e-mail and delete the material from any computer. 
Thank you for your cooperation.


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




RE: Can servlet write to file in /WEB-INF?

2002-06-24 Thread Les Hughes

Hi,

getRealPath() and its ilk are really very evil. If the webapp isn't exploded
into the filesystem - i.e. it's run straight from the war file then you
wont be able to write to the filesystem under WEB-INF anyway. And that's not
addressing *why* a webapp requires filesystem access and the related
security issues of allowing a servlet/jsp to write into a protected area
like WEB-INF either.

Anyway, my 2p says you should be doing something like:-

File temp =
(File)getServletContext().getAttribute(javax.servlet.context.tempdir);  

then make a dir/file under this for your output.

Hope this helps.

Les


 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
 Sent: 24 June 2002 09:13
 To: [EMAIL PROTECTED]
 Subject: RE: Can servlet write to file in /WEB-INF?
 
 
 Instead there is a method in the servlet context : 
 getRealPath(String relativefilename) - then you can open a 
 normal fileoutputstream.
 
 -Original Message-
 From: tamir [mailto:[EMAIL PROTECTED]]
 Sent: 24 June 2002 11:31
 To: 'Tomcat Users List'
 Subject: RE: Can servlet write to file in /WEB-INF?
 
 
 Hi,
 Making URLConnection to a directory under WEB-INF, is the 
 same like writing
 this url in the explorer.
 However, You can't go directly to any directory under WEB-INF 
 in that way,
 which justifies your failure of
 writing to this directory.
 
 You can write to files in this directory, if you don't use 
 URLConnection.
 That's what I think
 Tamir
 
 -Original Message-
 From: john-paul delaney [mailto:[EMAIL PROTECTED]]
 Sent: Saturday, June 22, 2002 10:48 AM
 To: TC user list
 Subject: Can servlet write to file in /WEB-INF?
 
 
 I was trying to see if I could write to a file in the 
 /WEB-INF directory but
 I couldn't get it to work - is there a problem with a servlet 
 writing to
 this directory or is it just me (again ;( ) ?
 
 thanks
 /j-p.
 
 URL url = context.getResource(/contextTest.txt);
 URLConnection con = url.openConnection();
 con.setDoOutput(true);
 OutputStream out = con.getOutputStream();
 PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
 pw.println(foo);
 pw.close();
 out.close();
 
 
 
 ---
  JUSTATEST Art Online
   www.justatest.com
 
 
 
 
 --
 To unsubscribe, e-mail:
 mailto:[EMAIL PROTECTED]
 For additional commands, e-mail:
 mailto:[EMAIL PROTECTED]
 
 --
 To unsubscribe, e-mail:   
 mailto:[EMAIL PROTECTED]
 For additional commands, e-mail: 
 mailto:[EMAIL PROTECTED]
 
  DISCLAIMER  
 This e-mail and any attachments thereto may contain information 
 which is confidential and/or protected by intellectual property 
 rights and are intended for the sole use of the recipient(s) 
 named above. 
 Any use of the information contained herein (including, but 
 not limited to, 
 total or partial reproduction, communication or distribution 
 in any form) 
 by persons other than the designated recipient(s) is prohibited. 
 If you have received this e-mail in error, please notify the 
 sender either 
 by telephone or by e-mail and delete the material from any computer. 
 Thank you for your cooperation.
 
 
 --
 To unsubscribe, e-mail:   
 mailto:[EMAIL PROTECTED]
 For additional commands, e-mail: 
 mailto:[EMAIL PROTECTED]
 

--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




RE: Can servlet write to file in /WEB-INF?

2002-06-24 Thread Chris Bailey

Right, keep in mind the whole WAR file aspect.  If your web app is not
packaged as a WAR file then it's less of an issue, and you could use
getRealPath, but if it is a WAR - even if it gets expanded by the container,
you can't use getRealPath and should write to a temp directory, or some
other directory you set up (you could store the location of this other
directory as a property in your web.xml file, etc.).

-Original Message-
From: Les Hughes [mailto:[EMAIL PROTECTED]]
Sent: Monday, June 24, 2002 3:08 AM
To: 'Tomcat Users List'
Subject: RE: Can servlet write to file in /WEB-INF?


Hi,

getRealPath() and its ilk are really very evil. If the webapp isn't exploded
into the filesystem - i.e. it's run straight from the war file then you
wont be able to write to the filesystem under WEB-INF anyway. And that's not
addressing *why* a webapp requires filesystem access and the related
security issues of allowing a servlet/jsp to write into a protected area
like WEB-INF either.

Anyway, my 2p says you should be doing something like:-

File temp =
(File)getServletContext().getAttribute(javax.servlet.context.tempdir);

then make a dir/file under this for your output.

Hope this helps.

Les


 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
 Sent: 24 June 2002 09:13
 To: [EMAIL PROTECTED]
 Subject: RE: Can servlet write to file in /WEB-INF?


 Instead there is a method in the servlet context :
 getRealPath(String relativefilename) - then you can open a
 normal fileoutputstream.

 -Original Message-
 From: tamir [mailto:[EMAIL PROTECTED]]
 Sent: 24 June 2002 11:31
 To: 'Tomcat Users List'
 Subject: RE: Can servlet write to file in /WEB-INF?


 Hi,
 Making URLConnection to a directory under WEB-INF, is the
 same like writing
 this url in the explorer.
 However, You can't go directly to any directory under WEB-INF
 in that way,
 which justifies your failure of
 writing to this directory.

 You can write to files in this directory, if you don't use
 URLConnection.
 That's what I think
 Tamir

 -Original Message-
 From: john-paul delaney [mailto:[EMAIL PROTECTED]]
 Sent: Saturday, June 22, 2002 10:48 AM
 To: TC user list
 Subject: Can servlet write to file in /WEB-INF?


 I was trying to see if I could write to a file in the
 /WEB-INF directory but
 I couldn't get it to work - is there a problem with a servlet
 writing to
 this directory or is it just me (again ;( ) ?

 thanks
 /j-p.

 URL url = context.getResource(/contextTest.txt);
 URLConnection con = url.openConnection();
 con.setDoOutput(true);
 OutputStream out = con.getOutputStream();
 PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
 pw.println(foo);
 pw.close();
 out.close();



 ---
  JUSTATEST Art Online
   www.justatest.com




 --
 To unsubscribe, e-mail:
 mailto:[EMAIL PROTECTED]
 For additional commands, e-mail:
 mailto:[EMAIL PROTECTED]

 --
 To unsubscribe, e-mail:
 mailto:[EMAIL PROTECTED]
 For additional commands, e-mail:
 mailto:[EMAIL PROTECTED]

  DISCLAIMER 
 This e-mail and any attachments thereto may contain information
 which is confidential and/or protected by intellectual property
 rights and are intended for the sole use of the recipient(s)
 named above.
 Any use of the information contained herein (including, but
 not limited to,
 total or partial reproduction, communication or distribution
 in any form)
 by persons other than the designated recipient(s) is prohibited.
 If you have received this e-mail in error, please notify the
 sender either
 by telephone or by e-mail and delete the material from any computer.
 Thank you for your cooperation.


 --
 To unsubscribe, e-mail:
 mailto:[EMAIL PROTECTED]
 For additional commands, e-mail:
 mailto:[EMAIL PROTECTED]


--
To unsubscribe, e-mail:
mailto:[EMAIL PROTECTED]
For additional commands, e-mail:
mailto:[EMAIL PROTECTED]



--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: Can servlet write to file in /WEB-INF?

2002-06-22 Thread Milt Epstein

On Sat, 22 Jun 2002, john-paul delaney wrote:

 I was trying to see if I could write to a file in the /WEB-INF
 directory but I couldn't get it to work - is there a problem with a
 servlet writing to this directory or is it just me (again ;( ) ?

 thanks
 /j-p.

 URL url = context.getResource(/contextTest.txt);
 URLConnection con = url.openConnection();
 con.setDoOutput(true);
 OutputStream out = con.getOutputStream();
 PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
 pw.println(foo);
 pw.close();
 out.close();

Well, I've never tried it before, but what you've got is pretty much
as described in an old Jason Hunter article:

http://www.javaworld.com/jw-12-1998/jw-12-servletapi-p3.html

I don't know if things have changed since then.

Of course, another issue is whether the user that the servlet is
running as has the appropriate permissions to write into that
file/directory.

Milt Epstein
Research Programmer
Systems and Technology Services (STS)
Campus Information Technologies and Educational Services (CITES)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: Can servlet write to file in /WEB-INF?

2002-06-22 Thread john-paul delaney

Thanks Milt... yes I'm reading servlet programming by the same author, he'd written a 
servlet example that reads and writes a counter to an external file resource but it 
seems the file location varies depending on the container implementation - I was 
trying to understand how to determine an exact location of a resource for reading 
from, and writing to.

Any further advice gratefully accepted.

/j-p.


On Sat, 22 Jun 2002, Milt Epstein wrote:

 Well, I've never tried it before, but what you've got is pretty much
 as described in an old Jason Hunter article:
 
 http://www.javaworld.com/jw-12-1998/jw-12-servletapi-p3.html
 
 I don't know if things have changed since then.
 
 Of course, another issue is whether the user that the servlet is
 running as has the appropriate permissions to write into that
 file/directory.
 
 Milt Epstein
 Research Programmer
 Systems and Technology Services (STS)
 Campus Information Technologies and Educational Services (CITES)
 University of Illinois at Urbana-Champaign (UIUC)
 [EMAIL PROTECTED]


---
 JUSTATEST Art Online
  www.justatest.com




--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]




Re: Can servlet write to file in /WEB-INF?

2002-06-22 Thread Milt Epstein

On Sat, 22 Jun 2002, john-paul delaney wrote:

 Thanks Milt... yes I'm reading servlet programming by the same
 author, he'd written a servlet example that reads and writes a
 counter to an external file resource but it seems the file location
 varies depending on the container implementation - I was trying to
 understand how to determine an exact location of a resource for
 reading from, and writing to.

 Any further advice gratefully accepted.

Not sure I have any other great suggestions.  Are you getting any kind
of error messages or anything in the logs?  Did you check in different
directories to see if the file was created somewhere?  Another
possibility is to try reading a file -- you might have to try it in a
few different locations to see what path (as the argument to
getResource()) matches up with what directory.


 On Sat, 22 Jun 2002, Milt Epstein wrote:

  Well, I've never tried it before, but what you've got is pretty much
  as described in an old Jason Hunter article:
 
  http://www.javaworld.com/jw-12-1998/jw-12-servletapi-p3.html
 
  I don't know if things have changed since then.
 
  Of course, another issue is whether the user that the servlet is
  running as has the appropriate permissions to write into that
  file/directory.
 
  Milt Epstein
  Research Programmer
  Systems and Technology Services (STS)
  Campus Information Technologies and Educational Services (CITES)
  University of Illinois at Urbana-Champaign (UIUC)
  [EMAIL PROTECTED]


 ---
  JUSTATEST Art Online
   www.justatest.com




 --
 To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
 For additional commands, e-mail: mailto:[EMAIL PROTECTED]


Milt Epstein
Research Programmer
Systems and Technology Services (STS)
Campus Information Technologies and Educational Services (CITES)
University of Illinois at Urbana-Champaign (UIUC)
[EMAIL PROTECTED]


--
To unsubscribe, e-mail:   mailto:[EMAIL PROTECTED]
For additional commands, e-mail: mailto:[EMAIL PROTECTED]