Glen Mazza wrote:

> Peter Crowther wrote:
>
>>> From: SOA Work [mailto:[EMAIL PROTECTED] 
>>
>>
>>
>> Check the Servlet Spec (version 2.4 is at
>> http://www.jcp.org/aboutJava/communityprocess/final/jsr154/
>> ) for questions of this kind.
>>
>>> From memory in both cases (so treat with caution):
>>
>>
>>
>>> 1.) am I allowed to call main methods or programms in my web
>>> applicatio?
>>
>>
>>
>> If you wish to be spec-compliant, no.  However, it should work depending
>> on Tomcat's security settings.
>>
>
> Really?  I thought you could do anything within a Servlet that you can
> do within normal Java code.  Also, a restriction on calling the
> "main()" method within a class seems nonsensical, because one can
> simply rename that method.
>
>
>>
>>> 2.) am I allowed to write files on the disk from within an web
>>> application? If I am, something went wrong while trieing ;-)
>>> Can i write anywhere or have I to write to my application dir or to
>>> temp dir or something.
>>
>>
>>
>>
>> If you wish to be spec-compliant, you can only write to a temporary
>> directory that you ask the context for.  However, this may or may not be
>> enforced depending on Tomcat's security settings.
>>
>
> This point I'm less sure on, but I would think it's the role of the
> *servlet container* to be spec-compliant, not the programmer of a
> servlet.  But FWIW, the Tomcat Administration Web Application
> (separate download in 5.5.x[1]) does alter the XML files located in
> the Tomcat /conf directory.  If the original questioner is having
> problems altering text files located on the server, perhaps the code
> for the Admin application would be a good reference for him.
>
> Glen
>
> [1] http://tomcat.apache.org/download-55.cgi
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
I know this is a late response in this thread, but I think the point is
still relevant....

Writing data is a perfectly normal operation in web applications. 
Admittedly the servlet spec is centered on writing to a database service
instead of the filesystem.  Webapp designers need to consider one or two
things from the beginning if writing to the filesystem. 

The first being deployment from a web archive (.war file) is intended to
be read-only by the servlet spec.  Best practice is to configure a path
to a place outside the webapp for writing data.  If the data needs to be
made available to the client, write a basic servlet to read the data and
write it to the client.  It'll make updating the webapp sooo much easier
when you don't have to worry about sorting out basic material in the
webapp from all the uploaded/dynamic material.

The second item to consider is path.  Relative paths are going to be
relative to the current working directory when tomcat was started, not
the webapp.  It'll cause loads of confusion trying to figure out where
that uploaded file went until you realize how the relative path was
computed.  ServletContext.getRealPath may help if you really want to
write to the webapp's folder, but this method only returns a path if the
webapp is deployed from an uncompressed folder (not a .war file).

Ok.  I miscounted.  Item three to consider: Writing to the filesystem
limits portability.  Not a problem if this is intended to be an in-house
solution, but might be something to consider when trying to sell your
solution to customers.

-- David


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

Reply via email to