我需要返回静态html文件的内容作为回复,例如,如果用户试图访问localhost:4567/hello.html
,我想显示另一个html文件而不是hello.html
他没有权限查看此页面。
现在我正在重定向到页面:
private void securityFilter(Request request, Response response) {
if (notAuthorized) {
response.redirect("/Error/AccessDenied.html");
}
}
但我不想重定向用户,我想返回状态代码为401
的响应,并将静态文件作为响应内容。
感谢。
答案 0 :(得分:1)
但我不想重定向用户,我想返回状态代码为401的响应,并将静态文件作为响应内容。
然后,您需要将HTML文件作为String读取并将其设置为响应正文。
private void securityFilter(Request request, Response response) {
if (notAuthorized) {
response.body(/* read HTML file as string */);
}
}