JSP错误页面 [英] JSP Error Pages

查看:77
本文介绍了JSP错误页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以在维护HTTP错误代码的同时拥有一个自定义错误页面(不能使用本身具有200个代码的错误页面捕获错误)?可以使用web.xml中的?还是可以直接在JSP中完成?

Is there a way to have a custom error page while maintaining the HTTP error code (not capturing the error with an error page that itself has a 200 code)? Can that have to be done using the in web.xml or can I do that directly in the JSP?

如果我使用response.sendError发送HTTP错误代码,则该页面上没有其他文本.我可以使用out.println()在页面上获取文本,但似乎无法打印出html,而只能打印基本文本.

If I send an HTTP error code using response.sendError then no other text appears on the page. I am able to get text on the page using out.println() but it doesn't seem to be able to print out html, just basic text.

推荐答案

您应该使用response.setStatus(int statusCode)将状态设置为404,同时仍然允许您发送自定义错误页面.

You should use response.setStatus(int statusCode) to set the status to 404 while still allowing you to send your custom error page.

这篇关于JSP错误页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆