java - 获取我的项目文件夹的路径

标签 java tomcat bootstrap-table to-json

在使用 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/

相关文章:

Java开源帮助台+工作流项目

java - 关于Tomcat for Java Server Based on sockets的问题

java - 如何在 Windows Vista 命令提示符中检查端口 8080?

javascript - 来自 Bootstrap 表的基于 Ajax 的数据的数据单元格上的工具提示

java - maven 中的配置文件 - 选择要构建的文件取决于 maven 中的配置文件

java - 我可以在 Google App Engine 中使用 JavaCompiler 吗?

java - Tomcat 身份验证和 Spring Security

twitter-bootstrap - Bootstrap 5 + Bootstrap-Table + X-editable 用于就地编辑表格单元格?

javascript - 隐藏 javascript 元素 - 不是常见问题

java - java中永久和持久的套接字连接