Spark java 返回 html - 500 内部服务器错误

问题描述

我想在我的 spark java 应用程序中关联 URL 和 index.html。如果我添加这个路由它工作正常:

get("/api/hello",(req,res) -> "hello");

我打开 URL:http://localhost:8080/api/hello 并看到“你好”

如果我添加这条路线:

get("/api/index",res) -> new ThymeleafTemplateEngine().render(
                new ModelAndView(new HashMap<>(),"/index.html")
        ));

webapp/index.html 中的这个 index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <Meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<H1>index</H1>
</body>
</html>

这个 web.xml

<web-app
        xmlns="http://java.sun.com/xml/ns/javaee"
        version="2.5">
    <filter>
        <filter-name>SparkFilter</filter-name>
        <filter-class>spark.servlet.SparkFilter</filter-class>
        <init-param>
            <param-name>applicationClass</param-name>
            <param-value>com.pavel.Main</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>SparkFilter</filter-name>
        <url-pattern>/api/*</url-pattern>
    </filter-mapping>
</web-app>

并打开http://localhost:8080/api/index

我看到 500 内部服务器错误

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)