There were some questions in the archives about how to write
data from HTML forms to a file on the server.  Specifically,
some people wanted to know how to get the path to a file in
the directory in which the Servlet was located.  I had
the same problem, and I found that the servlet was throwing
a fileNotFoundException when it looked for the file "names.txt",
even though names.txt was in the same directory.  I had a
suspicion that the server was actually running the servlet
in another directory. so I inserted the following code into
doGet();

                 String defaultPath = System.getProperty("user.dir");
                File here = new File(defaultPath);
                String[] contents = here.list();
                for (int index = 0; index < contents.length; index++)
                {
                        out.println(contents[index] + "<br>");
                }
                out.println("Directory: " + defaultPath + "<br>");

this allowed me to figure out where the servlet was beeing run
(about 3 directories above my servlet directory), wich allowed me
to create a fileWriter to the appropriate path.


--Monte Glenn Gardner

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to