servlet抛出异常到一个指定的jsp页面显示 请问如何实现?详细点... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 首先你要接住异常,在CATCH中跳转另外个页面就可以了,在把异常原因保存下,异常页面显示了思密达 try{做点啥。} catch (Exception e) { request.setAttribute("message", "xxx出错了"); request.getRequestDispatcher("error.jsp").forward(request,response); } 那我要把printStackTrace()里面的东西,在页面显示呢? request.setAttribute("massage",e.printStackTrace());然后在error.jsp页面取得massage Java codetry{做点啥。} catch (Exception e) { request.setAttribute("message", "xxx出错了"); request.getRequestDispatcher("error.jsp").forward(request,response); } request.setAttribute("message", "xxx出错了");//保存了错误信息在JSP上接受显示 ${message} 没人会这么做,谁会将这样的异常信息故意显示在页面?开发时,对于404、500之类的错误,会在配置文件中进行处理,进而转到一个配置好的错误页面提示。对于一些运行时异常,会直接在catch中进行处理。 <%@ page language="java" contentType="text/html;charset=UTF-8" isErrorPage="true" %><html> <head> <title>内部服务器错误</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="Cache-Control" content="no-cache"> <meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Expires" content="0"> <script language="JavaScript" type="text/JavaScript"> function showError() { var error = document.getElementById("exception"); var s = error.style.display; error.style.display = (s == "none") ? "" : "none"; } </script> </head> <body> <h2>内部服务器错误</h2> <hr> <div id="exception" style="color:blue"> <pre><% if (exception != null) { exception.printStackTrace(new java.io.PrintWriter(out)); exception.printStackTrace();} exception = (Throwable) request.getAttribute("exception");if (exception != null) { exception.printStackTrace(new java.io.PrintWriter(out)); exception.printStackTrace();} %> </pre> </div> </body></html> 一个关于java修改html的问题。急!急!急! 收到IBM笔试通知了,IBM笔试都考什么,笔过的进来分享一下经验 帮帮小弟啊 HTTP Status 404 - Servlet TestJSP is not available 数据传输问题,跪求 为什么老是找不到!!! 我想问一下,在用JSP编写Web页的时候,JavaScript应该怎么去利用? 刚接触JSP,求一段代码,请帮我解难,谢谢! 请帮帮忙 urlrewritefilter 急急急。。。! 通过网址注入的XSS问题 web下怎样加载src的文件? 急急急~~1个网站连策划到结束大概多少钱
try{
做点啥。
} catch (Exception e) {
request.setAttribute("message", "xxx出错了");
request.getRequestDispatcher("error.jsp").forward(request,response);
}
然后在error.jsp页面取得massage
try{
做点啥。
} catch (Exception e) {
request.setAttribute("message", "xxx出错了");
request.getRequestDispatcher("error.jsp").forward(request,response);
}
request.setAttribute("message", "xxx出错了");//保存了错误信息在JSP上接受显示 ${message}
没人会这么做,谁会将这样的异常信息故意显示在页面?开发时,对于404、500之类的错误,会在配置文件中进行处理,进而转到一个配置好的错误页面提示。对于一些运行时异常,会直接在catch中进行处理。
<head>
<title>内部服务器错误</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Cache-Control" content="no-cache">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<script language="JavaScript" type="text/JavaScript">
function showError() {
var error = document.getElementById("exception");
var s = error.style.display;
error.style.display = (s == "none") ? "" : "none";
}
</script> </head> <body>
<h2>内部服务器错误</h2>
<hr>
<div id="exception" style="color:blue">
<pre>
<%
if (exception != null) {
exception.printStackTrace(new java.io.PrintWriter(out));
exception.printStackTrace();
}
exception = (Throwable) request.getAttribute("exception");
if (exception != null) {
exception.printStackTrace(new java.io.PrintWriter(out));
exception.printStackTrace();
}
%>
</pre>
</div>
</body>
</html>