jsp报500jsp中异常对象为啥不能用,怎么解决

当前位置: →
→ jsp页面报错HTTPStatus500解决方法
jsp页面报错HTTPStatus500解决方法
& 作者:佚名 & 来源: 互联网 & 热度:
&收藏到→_→:
摘要: jsp页面报错 HTTP Status 500HTTP&Status&500&-&An&exception&occurred&processing&...
"jsp页面报错HTTPStatus500解决方法"::
jsp页面报错 http status 500http&status&500&-&an&exception&occurred&processing&jsp&page&/searchlist.jsp&at&line&27
--------------------------------------------
type&exception&report
message&an&exception&occurred&processing&jsp&page&/searchlist.jsp&at&line&27
description&the&server&encountered&an&internal&error&that&prevented&it&from&fulfilling&this&request.
exception&
:&an&exception&occurred&processing&jsp&page&/searchlist.jsp&at&line&27
24:&&jsp:usebean&id="jbean"&class="server.javabean"/&
26:&&&&&string&sql="select&*&from&student&order&by&id";
27:&&&&&java.util.list&list&=&sbean.getsearch(sql);
28:&&&&&for(java.util.iterator&it&=&list.iterator();it.hasnext();)
30:&&&&& jbean=(server.javabean)it.next();
stacktrace:
org.apache.jasper.servlet.jspservletwrapper.handle(jspservletwrapper.java:568)
org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:470)
org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:390)
org.apache.jasper.servlet.jspservlet.service(jspservlet.java:334)
javax.servlet.http.httpservlet.service(httpservlet.java:728)
root&cause&
server.sqlbean.getsearch(sqlbean.java:150)
org.apache.jsp.searchlist_jsp._jspservice(searchlist_jsp.java:104)
org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70)
javax.servlet.http.httpservlet.service(httpservlet.java:728)
org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:432)
org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:390)
org.apache.jasper.servlet.jspservlet.service(jspservlet.java:334)
javax.servlet.http.httpservlet.service(httpservlet.java:728)
note&the&full&stack&trace&of&the&root&cause&is&available&in&the&apache&tomcat/7.0.42&logs.
代码如下:
&%@&page&language="java"&import="java.util.*"&contenttype="text/&charset=utf-8"
&&&&pageencoding="utf-8"%&
string&path&=&request.getcontextpath();
string&basepath&=&request.getscheme()+"://"+request.getservername()+":"+request.getserverport()+path+"/"; 搜索此文相关文章:此文来自: 马开东博客
网址: 站长QQ
上一篇:没有了
jsp页面报错HTTPStatus500解决方法_JavaWeb相关文章
JavaWeb_总排行榜
JavaWeb_最新
JavaWeb_月排行榜
JavaWeb_周排行榜
JavaWeb_日排行榜欢迎大家,有任何问题可以给我留言,我会尽快回复你的,希望我们可以一起进步!...
项目异常处理:500、404、exception、403
第一步:你需要建立一个显示错误信息的jsp页面,内容如下:&%@ page language="java" contentType="text/ charset=UTF-8" pageEncoding="UTF-8" isErrorPage="true"%&
&%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&
&!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&
&meta http-equiv="Content-Type" content="text/ charset=UTF-8"&
&title&系统执行发生错误&/title&
&div&系统执行发生错误,信息描述如下:&/div&
&div&错误状态代码是:$ {pageContext.errorData.statusCode}&/div&
&div&错误发生页面是:$ {pageContext.errorData.requestURI}&/div&
&div&错误信息:$ {pageContext.exception}&/div&
错误堆栈信息:&br/&
&c:forEach var="trace" items="$ {pageContext.exception.stackTrace}"&
&p&$ {trace}&/p&
&/c:forEach&
当然这个只是用来显示获取错误相关的信息,里面包含了绝大多数的错误相关信息,你可以使用这些信息来定制你的错误显示。
第二步:配置web.xml文件,添加错误页。&error-page&
&exception-type&java.lang.Exception&/exception-type&
&location&/error.jsp&/location&
&/error-page&
这样的配置表示如果jsp页面或者servlet发生java.lang.Exception类型(当然包含子类)的异常就会转到error.jsp页面处理。&error-page&
&error-code&500&/error-code&
&location&/error.jsp&/location&
&/error-page&
这样配置也是可以的,表示发生500错误的时候,转到error.jsp页面处理。
是不是很简单,你可以配置多个&error-page&小节,将不同类型的错误转发到不同的错误处理页面,方法已经有了,赶快配置你的个性化错误信息显示吧。
也可以配置其他错误页面:&error-page&
&error-code&500&/error-code&
&location&/common/500.jsp&/location&
&/error-page&
&error-page&
&error-code&404&/error-code&
&location&/common/404.jsp&/location&
&/error-page&
&error-page&
&error-code&403&/error-code&
&location&/common/403.jsp&/location&
&/error-page&
压测netty框架,返回少量java.net.ConnectException:Connection timed out,优化代码
java.lang.ClassNotFoundException: org.apache.jsp.login_jsp
java异常处理及400,404,500错误处理
Spring MVC设置首页,403,404,500页面
java中的throw new Exception();和异常抛出
是什么原因导致404页面的出现呢?
Spring MVC,403,404,500页面
HTTP常见错误 400/401/403/404/500
没有更多推荐了,煅造一只小钢炮
良好的异常展现界面&500.jsp&
Web编程中,时常会出现后台报错的现象;原始界面,通常是这样展现异常的:
那么,如何才能自定义一个更加良好的界面,人性化,用户体验好的界面,就值得探索;本Demo实现的界面图是这样的:
以下是代码轰炸
1.web.xml配置
&/jsp/error/500.jsp&
response.setStatus(500);
// 获取异常类
Throwable ex = Exceptions.getThrowable(request);
// 编译错误信息
StringBuilder sb = new StringBuilder("错误信息:\n");
if (ex != null) {
sb.append(Exceptions.getStackTraceAsString(ex));
sb.append("未知错误.\n\n");
// 如果是异步请求,则直接返回信息
if (Servlets.isAjaxRequest(request)) {
out.print(sb);
// 输出异常信息页面
&%@page import="com.util.Servlets"%&
&%@page import="com.util.Exceptions"%&
&%@page import="com.util.StringUtil"%&
&%@page contentType="text/charset=UTF-8" isErrorPage="true"%&
&!DOCTYPE html&
&500 - 系统内部错误&
src="${pageContext.request.contextPath}/js/jquery.js"&&
href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.min.css" rel="stylesheet"&
href="${pageContext.request.contextPath}/bootstrap/css/bootstrap-theme.css" rel="stylesheet"&
src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.js"&&
language="javascript"&if(typeof jQuery == 'undefined'){ window.alert("没有jquery");}&
type="text/javascript"&
function change(value){
if(value == '1'){
$(".errorMessage").css("display", "none");
$(".errorMessage2").css("display", "block");
$(".errorMessage").css("display", "block");
$(".errorMessage2").css("display", "none");
class="container-fluid"&
class="page-header"&&系统内部错误.&&
class="errorMessage"&
错误信息:&%=ex==null?"未知错误.":StringUtil.toHtml(ex.getMessage())%& /& /&
请点击“查看详细信息”按钮,将详细错误信息发送给系统管理员,谢谢!/& /&
href="javascript:" onclick="history.go(-1);" class="btn"&返回上一页& &
href="javascript:" onclick="change('1');" class="btn"&查看详细信息&
class="errorMessage2" style="display:"&
&%=StringUtil.toHtml(sb.toString())%& /&
href="javascript:" onclick="history.go(-1);" class="btn"&返回上一页& &
href="javascript:" onclick="change('2');" class="btn"&隐藏详细信息&
out = pageContext.pushBody();
3.功能类,如Exceptions, StringUtil, Servlets
Exceptions.java
import java.io.PrintW
import java.io.StringW
import javax.servlet.http.HttpServletR
* 关于异常的工具类.
public class Exceptions {
* 将CheckedException转换为UncheckedException.
public static RuntimeException unchecked(Exception e) {
if (e instanceof RuntimeException) {
return (RuntimeException)
return new RuntimeException(e);
* 将ErrorStack转化为String.
public static String getStackTraceAsString(Throwable e) {
if (e == null){
return "";
StringWriter stringWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stringWriter));
return stringWriter.toString();
* 判断异常是否由某些底层的异常引起.
public static boolean isCausedBy(Exception ex, Class&? extends Exception&... causeExceptionClasses) {
Throwable cause = ex.getCause();
while (cause != null) {
for (Class&? extends Exception& causeClass : causeExceptionClasses) {
if (causeClass.isInstance(cause)) {
return true;
cause = cause.getCause();
return false;
* 在request中获取异常类
public static Throwable getThrowable(HttpServletRequest request){
Throwable ex = null;
if (request.getAttribute("exception") != null) {
ex = (Throwable) request.getAttribute("exception");
} else if (request.getAttribute("javax.servlet.error.exception") != null) {
ex = (Throwable) request.getAttribute("javax.servlet.error.exception");
StringUtil.java
public class StringUtil {
* 替换为手机识别的HTML,去掉样式及属性,保留回车。
public static String toHtml(String txt){
if (txt == null){
return "";
return org.apache.commons.lang3.StringUtils.replace(
org.apache.commons.lang3.StringUtils.replace(StringEscapeUtils.escapeHtml4(txt), "\n", "&br/&"),
"\t", "& & ");
Servlets.java
import javax.servlet.http.HttpServletR
public class Servlets {
* 是否是Ajax异步请求
public static boolean isAjaxRequest(HttpServletRequest request){
String accept = request.getHeader("accept");
String xRequestedWith = request.getHeader("X-Requested-With");
return ((accept != null && accept.indexOf("application/json") != -1 )
|| (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1));
设计一个500界面(400可以套用样式)
404/500/错误/异常/默认页面配置汇总
项目异常处理:500、404、exception、403
没有更多推荐了,1.web.xml 配置
&error-page&
&error-code&404&/error-code&
&location&/404.jsp&/location&
&/error-page&
&error-page&
&error-code&500&/error-code&
&location&/500.jsp&/location&
&/error-page&
2.定义404.jsp
&%@ page language="java" contentType="text/ charset=utf-8"
pageEncoding="utf-8" isErrorPage="true"%&
&%response.setStatus(HttpServletResponse.SC_OK); %&
&h1&您所查看的商品或页面没有找到&/h1&
3.定义500.jsp
&%@ page language="java" contentType="text/ charset=utf-8"
pageEncoding="utf-8" isErrorPage="true"%&
&%response.setStatus(HttpServletResponse.SC_OK); %&
&h1&很抱歉,您访问的页面出错了!&/h1&
&div id="errorMessageDiv" style="display:;"&
//全部内容先写到内存,然后分别从两个输出流再输出到页面和文件
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(byteArrayOutputStream);
printStream.println();
UserInfoDTO requestUser = (UserInfoDTO)request.getSession().getAttribute("userLogin");
printStream.println("用户信息");
if(requestUser != null){
printStream.println("账号:" + requestUser.getNickname());
printStream.println("账号:游客");
printStream.println("访问的路径: " + request.getAttribute("javax.servlet.forward.request_uri"));
printStream.println();
printStream.println("异常信息");
printStream.println(exception.getClass() + " : " + exception.getMessage());
printStream.println();
Enumeration&String& e = request.getParameterNames();
if (e.hasMoreElements()) {
printStream.println("请求中的Parameter包括:");
while (e.hasMoreElements()) {
String key = e.nextElement();
printStream.println(key + "=" + request.getParameter(key));
printStream.println();
printStream.println("堆栈信息");
exception.printStackTrace(printStream);
printStream.println();
out.print(byteArrayOutputStream);
//输出到网页
Calendar calendar = Calendar.getInstance();
/**按年月日来分*/
int year = calendar.get(Calendar.YEAR);//得到年
int month = calendar.get(Calendar.MONTH)+1;//得到月,因为从0开始的,所以要加1
int day = calendar.get(Calendar.DAY_OF_MONTH);//得到天
String saveurl = Constants.ROOTPATH + "errorLog/";
String path1 = saveurl + year + "/" ;
String path2 = saveurl + year + "/" + month + "/" ;
String path3 = saveurl + year + "/" + month + "/" + day + "/" ;
//建立按年月日文件夹,如果文件夹不存在,就建立新的文件夹。
FileOperate.newFolder(path1);
FileOperate.newFolder(path2);
FileOperate.newFolder(path3);
//System.err.print("AAAAA"+request.getRealPath("/errorLog"));
//项目的根目录
//File dir = new File(request.getRealPath("/errorLog"));
File dir = new File(path3);
//if (!dir.exists()) {
dir.mkdir();
String timeStamp = new SimpleDateFormat("yyyyMMddHHmmssS").format(new Date());
FileOutputStream fileOutputStream = new FileOutputStream(new File(dir.getAbsolutePath() + File.separatorChar + "error-" + timeStamp + ".txt"));
new PrintStream(fileOutputStream).print(byteArrayOutputStream); //写到文件
} catch (Exception ex) {
ex.printStackTrace();
阅读(...) 评论()JSP 500页面的异常信息打印__JSP
作者:用户
本文讲的是JSP 500页面的异常信息打印__JSP,
web开发中异常信息是很重的信息,对开发人员是其相当重要的,对这些异常信息进行转换为用户能理解的信息就更重要了~
在单纯的JSP开发中,处理异常信息一般使用web.xml来定义。
web中异常信息是很重的信息,对开发人员是其相当重要的,对这些异常信息进行转换为用户能理解的信息就更重要了~
在单纯的JSP开发中,处理异常信息一般使用web.xml来定义。
&error-page&
&error-code&400&/error-code&
&location&/400.&/location&
&/error-page&
&error-page&
&error-code&404&/error-code&
&location&/404.html&/location&
&/error-page&
&error-page&
&error-code&500&/error-code&
&location&/error.jsp&/location&
&/error-page&
这是很简单的。
如果现在想在页面中设置一个隐藏div来供开发人员查看异常信息呢。
整理下网站说的一些方法:
最常说的:
&%@page contentType="text/charset=Big5" isErrorPage="true"%&
&head&&title&出现错误&/title&&/head&
&H1&错误:&/H1&&%=exception%&
&H2&错误内容:&/H2&
exception.printStackTrace(response.getWriter());
因为这个页面调用了exception内置对象,所以isErrorPage必须为true。
这个是能打印出异常信息的,但是放入了response中,页面从头就开始打印异常信息,用户不明白异常信息~影响用户使用。
另一种常见方法:
不仅可以使用jsp内置exception对象来取得异常,也可以取得request中的attribute
&%@page contentType="text/charset=Big5" isErrorPage="true"%&
&head&&title&错误信息&/title&&/head&
错误码: &%=request.getAttribute("javax.servlet.error.status_code")%& &br&
信息: &%=request.getAttribute("javax.servlet.error.message")%& &br&
异常: &%=request.getAttribute("javax.servlet.error.exception_type")%& &br&
同理的还有
&%= exception.getMessage()%&
&%=exception%&
&c:out value="${requestScope['javax.servlet.error.message']}"/&
这个也可能打印异常信息,但有时只会打印出一个null.没有任何有价值信息。
-----------------------
还有一个特殊情况:
Error Page在IE下不能转发的问题
这是IE自身的设定导致的,经过百度,找到几个解决办法:
工具--&Internet选项--&高级---&显示http友好错误信息(取消选择) , 这样就可以了2, 设置指定错误页页状态为正常,来告诉IE这不是一个服务器错误, 从而不显示IE的自定义错误页 &%
response.setStatus(200); // 200 = HttpServletResponse.SC_OK%&3, 把错误页做大一点,弄个几百K 就可以显示错误页面 (加一个div块,display设为none就可以了),这个问题比较奇怪.
这个问题我还没有遇到过~先记录在这儿吧~~
现在能符合要求的处理方法是:
&%@ page language="java" contentType="text/ charset=GB18030"
pageEncoding="GB18030"%&
&%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&
&%@ page isErrorPage="true"%& //一定要写,不能显示错误
response.setStatus(HttpServletResponse.SC_OK); //这句也一定要写,不然IE不会跳转到该页面
String path=request.getContextPath();
&!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&
&meta http-equiv="Content-Type" content="text/ charset=GB18030"&
&title&Insert title here&/title&
&div&系统执行发生错误,信息描述如下:&/div&
以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索jsp
struts+spring+hibernate
,以便于您获取更多的相关知识。
弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率
40+云计算产品,6个月免费体验
稳定可靠、可弹性伸缩的在线数据库服务,全球最受欢迎的开源数据库之一
云服务器9.9元/月,大学必备
云栖社区(yq.aliyun.com)为您免费提供相关信息,包括
,所有相关内容均不代表云栖社区的意见!

我要回帖

更多关于 jsp空指针异常怎么解决 的文章

 

随机推荐