SERVLETJSP framework that automatically jumps to error pages

xiaoxiao2021-03-06  53

JSP has an instruction to define the JSP error page and jump to the page to output an error log when this JSP page is wrong. The following example: <% @ page errorpage = "ErrorPage.jsp"%> ErrorPage.jsp code code as follows: ..... <% @ page isrrorpage = "true"%> .... // Output error Diary <% = Exception.getMessage ()%> However, this can only be controlled in JSP page layer. In the implementation of J2EE, many cases are JSPs often as page display, and business-related database operations are executed in the background of servlet, and then jump a JSP display page after processing. This setting frame enables the MVC structure that makes the maintenance difficulty of the entire system greatly reduced. In the actual work, although the system uses the above settings framework, it is possible to pass the level of J2EE developers and the habits of programming, often encountering developers in the servlet to handle the possibility of error. One of the most common situations is that Catch an Exception E, then only calls E.PrintStackTrace (). The consequences of this are very serious. Once the exception occurs, the web page will appear in white screen, we can see from two aspects: (1) If it is the user used. He often don't know what it is, and it may not know that there is a mistake, continue to use the system, but this time the system has been mistaken, on the basis of the wrong basis, often cause more system level errors. (2) If it is a developer. The user reflects this error, but I don't know the reason. It can only be said that there is a white screen. Developers need to debug the wrong words, not get the input of the application server to see the wrong log, the reason why the positioning may be wrong, and then troubleshoot. Here, I will introduce an effective servlet error handling mechanism, which throws all the error contents of all Exception to the web page, so that the user has an error occurred immediately, and you can submit the error content to the developer positioning error. the reason. In fact, this mechanism is very simple. The idea is to define an abstract baseServlet class, which inherits the httpservlet. And add an abstract Abstract Public Void Doworkflow (HttpservletRequest Request, HttpservletResponse response) method, which is a way to all baseServlet subclasses and only need to implement. BaseServlet base class must of course implement service method - PUBLIC Final Void Service (HTTPSERVLETRESPONSE RESPONSE).

转载请注明原文地址:https://www.9cbs.com/read-117119.html

New Post(0)