SparkJava custom error page

2019-03-29 12:38发布

Does anyone know how to override existing 404 error page when using Spark micro web framework ?

The default error page is:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 404 </title>
</head>
<body>
<h2>HTTP ERROR: 404</h2>
<p>Problem accessing /strangepage. Reason:
<pre>    Not Found</pre></p>
<hr /><i><small>Powered by Jetty://</small></i>
</body>
</html>

I want to edit this custom error page (or maybe redirect it to a another route) :

get(new Route("/404") {
   @Override
   public Object handle(Request request, Response response) {
       response.type("text/html");
       return "Error page 404";
   }
});

标签: spark-java
7条回答
不美不萌又怎样
2楼-- · 2019-03-29 13:11

This is an old question, but since it is still answered.

Now you can handedl 404 as follows :

notFound("<html><body><h1>Custom 404 handling</h1></body></html>");
查看更多
登录 后发表回答