Solution to 500 Errors When Built in exception Object in JSP
- 2021-08-28 20:49:14
- OfStack
This article gives an example of how to solve the 500 error when exception object is built in JSP. Share it for your reference, as follows:
Try to use the built-in exception object of JSP and write the following three files. The idea is very simple. If the file index is empty, get throws an exception and handles it by error. jsp. However, it doesn't work normally, and the 500 error page of IE will appear. The environment is Tomcat 5.5, IE 6.0.
Someone posted the reason on the forum of sun, which is a setting of IE. Tomcat versions after 5.0 error page return error code 500 when processed. When IE gets code 500, it will check the length of the page. When the length is lower than a certain value, it will replace the established error page with its default 500 error page. It's called "user-friendliness" (this question took me a lot of time, and it was not friendly at 1 o'clock).
The solution can be to modify IE
Settings: Cancel the IE "Tools-Internet Options-Advanced-Show Friendly HTTP Error Messages" option; Or increase the length of your error page.
index.jsp
<html>
<head>
<title>index</title>
<head>
<body>
<form action="get.jsp" method="get">
<input type="text" name="text"><br>
<input type="submit" value="submit">
</form>
</body>
</html>
get.jsp
<%@page language="java" errorPage="error.jsp"%>
<html>
<head>
<title>index</title>
<head>
<body>
<%
String getText = request.getParameter("text");
out.print(getText);
if (getText.equals("")) {
out.print("empty");
throw new Exception("empty value");
}
%>
</body>
</html>
error.jsp
<%@page language="java" isErrorPage="true"%>
<html>
<head>
<title>index</title>
<head>
<body>
<%
out.print(exception.getMessage());
%>
</body>
</html>
Personal summary
The so-called increase in length, is in error. jsp file, copy more text content, can run normally.
I hope this article is helpful to everyone's JSP programming.