提问人:rollno748 提问时间:8/9/2023 最后编辑:Metroidsrollno748 更新时间:8/10/2023 访问量:34
无法使用 Spark Java 框架提供静态网页
Unable to serve a static web page using Spark java framework
问:
我有以下代码 - 它被配置为在包(src/main/resources/public)中提供静态网页
这不起作用,我在日志中也没有看到任何异常
public void startRestServer() {
try {
port(serverPort);
// staticFiles.location(System.getProperty("user.dir") + "/src/main/resources/public/");
staticFiles.location("/public");
connectionPool = SQLiteConnectionPool.getInstance(fileServerLocation, MIN_THREADS, MAX_THREADS, TIMEOUT);
staticFiles.externalLocation(this.fileServerLocation);
init();
awaitInitialization();
loadRestApiServices();
LOGGER.debug(String.format("REST services started :: http://%s:%s%s/",
InetAddress.getLocalHost().getHostAddress(), serverPort, uriPath));
} catch (Exception e) {
LOGGER.error("REST services failed to start", e);
}
}
我在下面配置了 API 路径
public void loadRestApiServices() {
UploadService uploadService = new UploadServiceImpl();
path(RestController.uriPath, () -> {
before("/*", (req, res) -> LOGGER.info("Received api call"));
get("/greet", (req, res) -> {
return "Hello Work !";
});
post("/upload", (req, res) -> {
JSONObject jsonObject = new JSONObject(req.body());
uploadService.uploadCustomPlugin(jsonObject);
return null;
});
after((req, res) -> res.header("Content-Encoding", "gzip"));
});
预期结果:
我希望它向用户提供索引 .html - 这基本上是一个帖子表单,用于上传文件
答: 暂无答案
下一个:重定向到其他网站
评论