在使用 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.
最佳答案
这是跨域问题,bootstrap table 不支持 file://
url,请使用 Web 服务器来运行您的代码。这里有个问题可以帮到你:https://github.com/wenzhixin/bootstrap-table/issues/230
关于java - 获取我的项目文件夹的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33660218/