The exception information in web development is very heavy information, it is very important to the developer, it is more important to convert these exception information to the information that the user can understand ~
In the simple JSP development, the handling of exception information is generally defined using Web.xml.
02 |
<error-code>400</error-code> |
03 |
<location>/400.html</location> |
07 |
<error-code>404</error-code> |
08 |
<location>/404.html</location> |
12 |
<error-code>500</error-code> |
13 |
<location>/error.jsp</location> |
This is very simple.
If you want to set up a hidden div on the page now to allow developers to view the exception information.
Sort out some of the ways the site says:
Most often said:
01 |
<% @page contenttype= "Text/html;charset=big5" iserrorpage= "true"%> |
08 |
Exception.printstacktrace (Response.getwriter ()); |
Iserrorpage must be true because this page invokes the exception built-in object.
This is able to print out the exception information, but put in the response, the page began to print abnormal information, the user does not understand the exception information ~ Impact user use.
Another common method:
Not only can you use the JSP built-in exception object to get the exception, you can also get the attribute in the request
1 |
<% @page contenttype= "Text/html;charset=big5" iserrorpage= "true"%> |
5 |
Error code: <%=request.getattribute ("Javax.servlet.error.status_code")%> <br> |
6 |
Info: <%=request.getattribute ("Javax.servlet.error.message")%> <br> |
7 |
Exception: <%=request.getattribute ("Javax.servlet.error.exception_type")%> <br> |
Similarly, there are
<%= exception.getmessage ()%>
<%=exception%>
<c:out value= "${requestscope[' Javax.servlet.error.message ']}"/>
This may also print exception information, but sometimes only a null is printed. There is no valuable information.
-----------------------
There is also a special case:
Error Page cannot be forwarded under IE.
This is the setting of IE itself, after Baidu, find several solutions:
1, IE set tool-->internet option--> advanced---> Display HTTP friendly error messages (deselect), so that's it.
2, set the specified error page status to normal, to tell IE this is not a server error, so do not show IE's custom error page
<%
Response.setstatus (200); = Httpservletresponse.sc_ok
%>
3, make the error page bigger, get a hundreds of K can display error page (plus a div block, display set to none on it), this question is more strange.
This question I have not met ~ First record here ~ ~
Now the processing method that meets the requirements is:
01 |
<%@ page language= "java" contenttype= "text/html; charset=gb18030 " |
02 |
pageencoding= "GB18030"%> |
03 |
<%@ taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%> |
04 |
<%@ page iserrorpage= "true"%>//must write, cannot display error |
06 |
Response.setstatus (HTTPSERVLETRESPONSE.SC_OK); This sentence must also be written, or IE will not jump to the page |
07 |
String Path=request.getcontextpath (); |
09 |
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" > |
12 |
<meta http-equiv= "Content-type" content= "text/html; charset=gb18030 "> |
13 |
<title>insert title here</title> |
17 |
An error occurred in the <div> system execution, the information described below:</div> |