javaxmljspfilestreamresult

XML + Write to Relative Path


I have the following folder structure

TempProj
!-js
!-jsp
!-WEB-INF
  !-classes
  !-lib

Inside my lib folder, I have a java file that creates an XML file, I actually need the file to be generated inside the jsp folder.

I'm creating using StreamResult result = new StreamResult("test.xml");

I've tried giving the following paths "../../jsp/text.xml". Since I've deployed it, the path has to be relative.

Any help!!


Solution

  • What App Server you using ? If you are using Websphere (possibly others, but I don't know) , you might have to set up a 'file url' and use JNDI to delegate the job of finding the directory to the App Server itself.

    As an experiment to shed more light on the problem, you could try something like:

    File nopath = new File("text.xml");
    System.out.println(nopath.getCanonicalPath());
    

    And:

    File relpath = new File("../../jsp/text.xml");
    System.out.println(relpath.getCanonicalPath());
    

    I wonder if you are going to be able to do this...I have a feeling (and that's all it is , please check!) that App Server's Security manager might not like you trying to traverse up and out of the directory....

    You might want to reconsider not creating a file-on-disk - instead create a new servlet that dynamically serves up the XML...(presuming that you need the client-browser to see some XML ultimately...).