At 06:12 PM 10/16/2003, you wrote:
>Running Tomcat 4.1.27, I'm currently deploying via the "install" task in
>the Ant script supplied with Tomcat, so all my files reside outside of the
>Tomcat directory. Otherwise, everything's pretty normal (Tomcat resides
>in C:\tomcat).
>
>Just for curiosity's sake, could I find out what methods there are
>(instead of only what someone thinks is best?). 6 months down the road my
>situation might change (this is still in development & real deployment
>might be different) and it'd be nice to know what my options
>are. Suggestions for which method is best are of course still welcome.
You basically have two options:
(1) Write the file and directly reference it. For example, if you write
your file into $TOMCAT/webapps/appname/myfile.html, then you can point your
browser directly to it and it can download. If you always deploy your app
exploded (not as a .war), then this is fine because you can use java's
java.io.* classes to directly write to your filesystem. This method limits
your deployment options. There's some way to construct the filesystem path
to your webapp root through the javax.servlet.* classes, but I forgot what
it is -- instead, pass the value in as an init parameter (jndi, servet init
param, outside config file -- take your pick) to your servlet. It would be
something like:
// In your servlet
String webAppRoot = MyConfig.getWebAppRootPath();
File file = new File(webAppRoot+"/myfile.html");
// Write whatever data you want to the File
(2) Write the file (anywhere), then make it available to users through a
Servlet which serves the content. Instead of writing a physical file to
your webapp file tree, create a servlet that takes an argument specifying
which file the user desires. An example URL would look like:
http://server.com/myApp/NewFileServlet?path=reports.cash.mostRecent
This Servlet would take into account session info, the path parameter,
security considerations, etc, to find the correct file and serve it back to
the user. This gives you the choice to store the file anywhere --
database, xml, remote server, anywhere -- and then serve it back up when
requested.
You also avoid any deployment problems because you're not relying on the
underlying filesystem to support your application's new files.
Hope that sheds some light on the topic ... (1) is quicker and easier, (2)
is more robust and flexible, but is more involved to implement. Take your
pick based on whatever other requirements you have. If you have more
questions, don't hesitate to ask.
justin
>Thanks
>Jason
>
>Justin Ruthenbeck wrote:
>
>>
>>Yes, it is possible. Give us an idea of your deployment setup (are you
>>deploying as a .war file? Using default root paths? Anything special?)
>>and we can suggest the best way to go about doing it.
>>
>>justin
>>
>>At 04:16 PM 10/16/2003, you wrote:
>>
>>>Is it possible, in a servlet, to write to a temporary file in a location
>>>that I would then be able to link to so the users can download? I
>>>couldn't find any information indicating either way.
>>>
>>>Thanks
>>>Jason
>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
>>>For additional commands, e-mail: tomcat-user-help@(protected)
>>
>>____________________________________
>>Justin Ruthenbeck
>>Software Engineer, NextEngine Inc.
>>justinr - AT - nextengine DOT com
>>Confidential
>> See http://www.nextengine.com/confidentiality.php
>>____________________________________
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
>>For additional commands, e-mail: tomcat-user-help@(protected)
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
>For additional commands, e-mail: tomcat-user-help@(protected)
____________________________________
Justin Ruthenbeck
Software Engineer, NextEngine Inc.
justinr - AT - nextengine DOT com
Confidential
See http://www.nextengine.com/confidentiality.php
____________________________________
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@(protected)
For additional commands, e-mail: tomcat-user-help@(protected)