当我通过 Intellij 运行我的网络应用程序时,它工作正常。转到localhost:4567
并且apache打开index.html页面。但是当我部署 war 文件并使用 java -jar project.war
运行它时,它会下载 index.html 页面
我的资源中有文件夹public
。 index.html 就在那里
public static void main(String[] args) {
ProcessBuilder process = new ProcessBuilder();
Integer port;
if (process.environment().get("PORT") != null) {
port = Integer.parseInt(process.environment().get("PORT"));
} else {
port = 4567;
}
port(port);
staticFileLocation("/public");
}
我错过了什么?如果您需要任何其他信息,请在评论中告诉我
最佳答案
您应该使用2.7.2或更高版本,以前的版本有bug
关于java - SparkJava Web浏览器下载html文件而不是在部署war文件时显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57109926/