java - Spark java返回html - 500内部服务器错误
问题描述
我想在我的 spark java 应用程序中关联 URL 和 index.html。如果我添加这条路线,它可以正常工作:
get("/api/hello", (req, res) -> "hello");
我打开 URL:http://localhost:8080/api/hello
并看到“你好”
如果我添加这条路线:
get("/api/index", (req, 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 内部服务器错误
解决方案
推荐阅读
- r - R:在 Shiny 中使用公式对象来检索描述性统计数据
- javascript - 嵌套的 .then 的 JS 返回值
- c - 与哨点值相反
- c++ - c++ (sys/socket.h) 客户端重试连接到服务器导致 seg 错误
- wordpress - Wordpress 中的 Google Places 自动完成仅澳大利亚限制
- ios - Apple TV - 如何在 UISegmentedControl 中实现粘性焦点选择?
- c# - 访问具有多个泛型类型的类中的静态变量
- c - 如何按字母顺序排列字符串并返回指向已排序字符数组的指针?
- python - Python - 在二进制文件中写入特定数量的字节
- python - 如何通过 Http 在 Python 中从 Dart 中读取 protobuf 数据包