JSPservlet Getting Started] JSP Error Processing

xiaoxiao2021-03-06  26

When you start writing JSP, you will always be troubled by JSP, if you don't know the beginner's initiator between JSP and Servlet, what is just a pile of removal news, even exception happening, Although these messages include detailed error messages, it is not friendly for beginners, and it is difficult to read. Basically, just understand the operational relationship between JSP and servlet, and learn about the Java compile information and exception processing. To understand the error report page generated by the error when writing a JSP page, it is not difficult. We know that JSP will change to servlet, and the runtime is really a servlet class, so the error may occur at two times: one is a JSP converted to servlet original code, because JSP syntax errors can not generate a servlet original code, Or converted to a servlet code, but compile time compiler checks out errors, which is called Translation Time Processing Errors; the second error occurs when the client requests the servlet, because the program logic or running is not considered The error is generated, which is called the Client Request Time Processing Errors. How do I discriminate the type of error occurrence at the JSP runtime? If the error report page appears ".... Encountered An Internal Error ...", it may be a conversion period error, or "generated servlet error: [javac] compling 1 source file ...." It may be that the compiler discovers errors when compiling the Servlet code, this time you have to check if the JSP syntax has an error, or the program logic has obvious ways to check the compiler. What is the program logic clearly makes the compiler check the error? An error that initiator is more frequent but not easy to check, may be "excess break", for example: <% @ page contenttype = "charset = big5" errorpage = "errorhandler.jsp"%> <% throw new exception "This is a pretended error, pure throws out exception ^ _ ^");%> This JSP program is not wrong, we just throw out an exception, but notice that it is the most empty, After converting to servlet, this line will actually be converted to out.write ('/ r'); and before this line, we have dropped out of an exception, in other words, Out.write ('/ r'); This line will never be executed, this logic error, the compiler is an out-of-one, and the error page will return "unreachable stat", correct this error, is to delete the extra broken lines in the JSP page. If the compiled servlet After the user request, the exception is thrown during the running process, if this exception is not processed, the last will be processed by the Container, and the Container will transfer the message back to the client. It is basically ".... Encountered An Internal Error ....", but the exception stacking message will appear in the rendering page, so you can judge that it should be Client Request Time Processing Errors.

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

New Post(0)