Search code examples
javatomcatbootstrap-tableto-json

Get the path of my project's folder


In build a web application with netbeans, in some point I extract an arrayList to json format.

public void convertToJSON(ArrayList list){

     ObjectMapper mapper = new ObjectMapper();

     try{
          mapper.writeValue(new File("C:\\temp\\data.json"), list);
        }catch(JsonGenerationException e){
          e.printStackTrace();
        }catch(JsonMappingException e){
          e.printStackTrace();
        }catch (IOException e){
          e.printStackTrace();
        }
}

and this creates the file C:\temp\data.json. How can I create this file inside my project folder where JSPS's exist? I tried determine the location with

String dir = System.getProperty("user.dir");

but this created the file in C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.15\bin. I want to create the file inside the projects folder in order to use it to show my data in bootstrap table. There I define the location of my data by

data-url="data.json"

I tried this data-url="C:\temp\data.json" but i got an error

XMLHttpRequest cannot load file:///C://temp//data.json?order=desc&limit=10&offset=0. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

Solution

  • This is cross domain problem, bootstrap table does not support file:// url, please use an web server to run your code. Here is a issue can help you: https://github.com/wenzhixin/bootstrap-table/issues/230