如何在jsf中从bean抛出404 [英] How to throw 404 from bean in jsf
本文介绍了如何在jsf中从bean抛出404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要抛出404并将访问者带到特定页面.我正在尝试以下代码:
I need to throw 404 and take visitor to a specific page. I am trying with following code:
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
externalContext.setResponseHeader(Common.LOCATION, "browse_by_category.xhtml?category=CATEGORY_ALL");
facesContext.responseComplete();
404发生,但是没有重定向到Browse_by_category.xhtml页面. 任何帮助将不胜感激.
404 happens but redirection to the browse_by_category.xhtml page does not happen. Any help will be greatly appreciated.
推荐答案
根据您的评论,请尝试以下操作:
According to your comment please try this:
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
externalContext.setResponseStatus(HttpServletResponse.SC_NOT_FOUND);
//externalContext.setResponseHeader(Common.LOCATION, "browse_by_category.xhtml?category=CATEGORY_ALL");
externalContext.dispatch("browse_by_category.xhtml");
facesContext.responseComplete();
这篇关于如何在jsf中从bean抛出404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文