最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。
When a Servlet throws an exception, the Web container uses the exception-type of the element web.xml search for configurations that match the type of exception thrown in the.
You must be in the Hypothetically, there is one If you want to have a common error handler for all exceptions, you should define the following The following is about the above Servlet ErrorHandler is defined in the same way as other Servlet, and in the If an error status code occurs, whether it is 404 (Not Found not found) or 403 (Forbidden prohibited), ErrorHandler’s Servlet is called. If the Web application throws a You can define different error handlers to handle different types of errors or exceptions. The above examples are very general, and I hope you can understand the basic concepts through the examples. The following is a list of request attributes that can be accessed by the error-handling Servlet to analyze the nature of the error / exception. Serial number Attribute & description 1 2 3 4 5 6 The following is an example of Servlet that will handle the error handler when any error or exception that you define occurs. This example gives you a basic understanding of exception handling in Servlet, and you can write more complex exception handling applications using the same concepts: Compile in the usual way Let’s do it in Now, try to use a Servlet that generates an exception, or enter an incorrectURL, which will trigger the Web container call web.xml for use in error-page element to specify the corresponding Servlet call to a specific exception or HTTP status code. 2.11.1. Web.xml configuration ¶
ErrorHandler is called when any defined exception or error occurs. The following will be the web.xml item created
error-page instead of defining a separate error-page elements:<error-page> <exception-type>java.lang.Throwableexception-type > <location>/ErrorHandlerlocation> error-page>
web.xml points to pay attention to in exception handling:
web.xml configure it. ServletException or IOException ,then the Web container calls the ErrorHandler Servlet. Request Properties-error / exception ¶
javax.servlet.error.status_code the attribute gives a status code, whichcan be stored and analyzed after being stored as a java.lang.Integer data type. javax.servlet.error.exception_type this property gives information aboutthe exception type, which can be stored and parsed after it is stored as a java.lang.Class data type. javax.servlet.error.message this property gives information about the exact error message, which can be stored and parsed after being stored as a java.lang.String data type. javax.servlet.error.request_uri this property gives information about URL calling Servlet, which can be stored and analyzed after being stored as a java.lang.String data type. javax.servlet.error.exception this attribute gives the information generated by the exception, which can be stored and analyzed after being stored as a java.lang.Throwable data type. javax.servlet.error.servlet_name this attribute gives the name of the Servlet, which can be stored and parsed after being stored as a java.lang.String data type. Servlet error Handler example ¶
//Import necessary Java libraries import java.io.*; import javax.servlet.*; import javax.servlet.http.*; import java.util.*; //Extend HttpServlet Class public class ErrorHandler extends HttpServlet { // Method for handling GET method requests public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Throwable throwable = (Throwable) request.getAttribute("javax.servlet.error.exception"); Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code"); String servletName = (String) request.getAttribute("javax.servlet.error.servlet_name"); if (servletName == null){ servletName = "Unknown"; } String requestUri = (String) request.getAttribute("javax.servlet.error.request_uri"); if (requestUri == null){ requestUri = "Unknown"; } // Set response content type response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String title = "Rookie Tutorial Error/Exception information"; String docType = "\n"; out.println(docType + "\n" + "
Example demonstration of abnormal information in the rookie tutorial
"); if (throwable == null && statusCode == null){ out.println("Error message lost
"); out.println("Please return \"" + response.encodeURL("http://localhost:8080/") + "\">homepage."); }else if (statusCode != null) { out.println("error code : " + statusCode); }else{ out.println("error message
"); out.println("Servlet Name : " + servletName + ""); out.println("Exception : " + throwable.getClass( ).getName( ) + ""); out.println("request URI: " + requestUri + "
"); out.println("abnormal information: " + throwable.getMessage( )); } out.println(""); out.println(""); } // Method for handling POST method requests public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { doGet(request, response); } } ErrorHandler.java to put your class files in web.xml add the following configuration to the file to handle exceptions:
ErrorHandler and display the appropriate message For example, if you enter an incorrect URL (such as: http://localhost:8080/TomcatTest/UnKonwPage ), it will display the following result: