August 29th, 2002, 07:10 AM
Servlet security and finding path to server....
Hi. I am relatively new to servlets and have a couple of questions. From what I understand a servlet can create files on the server as long as its from the web address at which it originated. Is that correct? Here is the reason that I ask.
I have some applet/servlet communication. In the applet, users can draw a picture (much like paint). When they are finished, the applet sends the picture to the servlet. I then need the servlet to create a new file in a specified folder and save the picture to it. Originally, I was using Tomcat 4.0.3 on my computer running as a local host to test my code. Using getServletContext.getRealPath("/") I was able to get it to work.
Now I have a web host that is running Apache JServ. They give you a "servlets" folder to load your servlet into and it should work from there. The servlet is communicating just fine, but getRealPath("/") now returns null. I've also tried getResource("/"), but that pulls a Server 500 error.
If anyone can tell me if what I'm trying to do is possible and can offer any other suggestions, I'd really appreciate it. Thank you all in advance.
August 31st, 2002, 04:05 AM
As far as I know, permission to write to the disk is controlled by the operating system, and determined by the user the App server is running as. There's not guarantee in a server environment that the App server user would have access to the disk.
From the javadoc for ServletContext.getRealPath()
I don't know if that applies to you or not.