Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create a text file from server side

 
Tien Duong Nguyen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

My JSP is trying to create a new file from the server. Here is the code :

<%
String path = application.getRealPath("/toto.xml");
FileWriter writer = new FileWriter(path);
writer.write("<?xml version='1.0'?>");
out.write( "Success in creating toto.xml! " );

%>

However, I always get the error "Permission Denied", I guess i need to do some authentication, i.e. provide user name and password but not sure how to do it ?

Any help is greatly appreciated.

Regards,

Andy
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the user under which your container is running have sufficient permissions to write to that file?
 
Tien Duong Nguyen
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My JSP , when deployed in localhost (tomcat ), can create the file but when it is deployed in the server ( tomcat ), could not and the exception is "Permission denied".

I also guess that the problem is the tomcat container does not have the right to write the file, and I need to do some authentication, e.g. provide the user name and password that is used for FileTransfer. But I do not know how to do the authentication.

Any help is greatly appreciated.

Regards,

Andy.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic