java Exception 错误 转为字符串 换行

来源:互联网 发布:09淘宝店 编辑:程序博客网 时间:2024/04/24 06:00
<%@page pageEncoding="UTF-8" %>
<%@page import="java.io.Writer"%>
<%@page import="java.io.PrintWriter"%>
<%@page import="java.io.StringWriter"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>


<title>ERROR</title>


</head>


<body>
<%
String info="";
StringWriter writer=null;
try{
Exception  exception = new Exception("错误。");
writer = new StringWriter();
exception.printStackTrace(new PrintWriter(writer));
info = writer.getBuffer().toString();
info = info.replace("\n","<br>&nbsp;&nbsp;&nbsp;&nbsp;");
}catch(Exception e)
{}
finally{
if(writer != null)
try {
writer.close();
}catch (Exception e) {
e.printStackTrace();
}


}



%>
异常对象: <s:property value="exception"/><br>
异常堆栈信息:<br>
<%=info %>
<s:property value="exceptionStack"/>
</body>
</html>