写在前面:
在web项目中,可能会出现404、500等错误页面,给用户体验不怎么好,所以我们可以对这些错误页面进行友好的处理。
步骤:
1.配置web.xml:
<!--错误页面友好显示--><error-page><error-code>404</error-code><location>/commons/error.jsp</location></error-page><error-page><error-code>500</error-code><location>/commons/error.jsp</location></error-page><error-page><error-code>java.lang.Exception</error-code><location>/commons/error.jsp</location></error-page>
2.在error.jsp页面进行设置:
<%@pagelanguage="java"import="java.util.*"pageEncoding="UTF-8"isErrorPage="true"%><body><%response.setStatus(200);%>很抱歉!你访问的页面不存在......</body>
这里主要是 设置isErrorPage="true" 然后加上response.setStatus(200); 即可。
嘻嘻~~~到这里就已经成功啦。。。。。