File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Security and the fly likes Access denied when creating a new XML file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark "Access denied when creating a new XML file" Watch "Access denied when creating a new XML file" New topic
Author

Access denied when creating a new XML file

Nawed Shaikh
Greenhorn

Joined: Mar 12, 2013
Posts: 8
I have tried to create a new XML through JSP page. It works fine but i have Access denied exception from server.
I am using Apache Tomcat as server and Netbeans as IDE.
Here is the Code :

How can i solve this,i know i have to change some settings of apache server but i dont know how to do.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42363
    
  64
NetBeans is an IDE, it has no bearing on runtime behavior (I hope you're not trying to run a web app inside of an IDE, it usually ends in tears).

i know i have to change some settings of apache server

I think that's very unlikely. It seems an issue of file permissions, possibly in conjunction with restrictions put in place by a security manager in that Tomcat. The problem is that "CreateXML.xml" is a relative path, and it is almost certainly a different path than you think it is - in this case, apparently one to which the account under which Tomcat runs has no access (or which the security manager denies access to). So make that an absolute path, and remember: never, ever use a relative path in a web app, the results are unpredictable. If it still doesn't work if the code writes to a file that you know can be accessed by the account under which Tomcat runs, examine which restrictions the security manager puts in place, if any.


Ping & DNS - my free Android networking tools app
Nawed Shaikh
Greenhorn

Joined: Mar 12, 2013
Posts: 8
well thank you for reply and absolute path worked fine like C:/xml/CreateXML.xml. etc
one to which the account under which Tomcat runs has no access (or which the security manager denies access to)

Yes! that is what the question was all about. So, how can i remove those restrictions that apache server has.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42363
    
  64
By "Apache", do you mean Tomcat? Or httpd? I think you're talking about Tomcat, but the vast majority of people mean httpd when they say "Apache", so using it to mean Tomcat would be confusing.

Assuming you mean indeed Tomcat, there's a lot more to this question. There are very good reasons why the account Tomcat runs under might not have access to an arbitrary directory, or why there might be a security manager in use. Are you certain you know why those restrictions are currently in place, and that it would be safe to remove them?
Nawed Shaikh
Greenhorn

Joined: Mar 12, 2013
Posts: 8
By "Apache", do you mean Tomcat? Or httpd? I think you're talking about Tomcat, but the vast majority of people mean httpd when they say "Apache", so using it to mean Tomcat would be confusing.

Yes you Are right its tomcat i was to use "apache tomcat".
Well I am creating an Exam Portal, in it there is a JSP calcresult.jsp which calculates the result of exam and shows the result of the exam.
After that it also creates an xml file which stores the result , so that examiner can evaluate the result later.
But as you know i got an exception, and i did use the absolute path as you suggested and it worked well !
but now i am not able to acces this xml file through AJAX. Is there any suggestion how i can solve this?
Well to be honest this is my first project i am working on , so i apologise for silly questions and information.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42363
    
  64
Where exactly is that file on the server? In general server-side files are not accessible from the client. If you want the file to be accessible from a browser, you'd need to put it into a publicly accessible directory (like the root directory of your web app).
Nawed Shaikh
Greenhorn

Joined: Mar 12, 2013
Posts: 8
Sorry i have been a busy for a while and thank you for your time all the way.
Where exactly is that file on the server?

Well i was trying to save the file on the same directory as Web pages but it didn't worked. code like :

But i realised that I have used NetBeans, So i tried the absolute path of the workspace and It worked!
But i am still confused over 1 thing if path of the workspace worked why the relative path like : "CreateXML.xml" didn't worked ?.
But anyway thank you once again for your valuable time that you have given here .
Nawed
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Access denied when creating a new XML file