JSP中统一错误信息输出
一、在JSP页面中
1、在jsp页面中加入<%@ page errorPage="error.jsp"%>
指定错误处理页面为error.jsp
2、在error.jsp中将错误信息输出显示
<%@ page isErrorPage="true" import="java.io.*"%>
<%=exception.getMessage()%><br>
<%=exception.getLocalizedMessage()%>
<%
StringWriter sw=new StringWriter();
PrintWriter pw=new PrintWriter(sw);
exception.printStackTrace(pw);
out.print(sw);
%>
二、在web.xml配置文件中
<error-page>
<error-code>404</error-code>
<location>/pageNotFound.htm</location>
</error-page>
<error-page>
<error-code>505</error-code>
<location>/internalError.htm</location>
</error-page>
<error-page>
<exception-type>java.lang.NumberFormatException</exception-type>
<location>/internalError.htm</location>
</error-page>
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步