在使用netbeans构建Web应用程序时,有时我将arrayList提取为json格式。
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();
}
}
这将创建文件
C:\temp\data.json
。如何在存在JSPS的项目文件夹中创建此文件?我尝试确定位置String dir = System.getProperty("user.dir");
但这会在
C:\Program Files\Apache Software Foundation\Apache Tomcat 8.0.15\bin
中创建文件。我想在项目文件夹中创建文件,以便使用它在bootstrap table
中显示我的数据。在那里,我通过以下方式定义了数据的位置data-url="data.json"
我尝试了这个
data-url="C:\temp\data.json"
但出现错误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.
最佳答案
这是跨域问题,引导程序表不支持file://
url,请使用Web服务器运行您的代码。这是一个可以帮助您的问题:https://github.com/wenzhixin/bootstrap-table/issues/230
关于java - 获取项目文件夹的路径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33660218/