Common errors and workarounds for Web programs

Source: Internet
Author: User

404 Causes of Errors and solutions

In the beginning of web application development, often see the page appears 404 this number, we generally call the operation produced 404 errors. Similar to the number 404, it is possible to see on the page 405, 500 of the two numbers, they are the server after the client's request, returned to the client on the execution of the results of a status code description. If you do not see the expected page in the run Results page, but see the 404, 405, 500 such a number, then the representative of the server to tell the client to run the error, to master what error situation to produce the corresponding number will be beneficial to solve the problem.
404 The reason for this is that the Web server (container) cannot find a corresponding resource based on the requested address, and 404 error is present in the following situations:
The address entered is incorrect (the application name is not case-correct, the name is spelled incorrectly)
Two inconsistencies in and in the Web. xml file
No project deployed under Tomcat's WebApps
The structure of the Web project deployment does not follow the specification of the servlet
The specific solution is to check each of the 4 cases mentioned above.

How the container finds the service () method

When I enter this address in the browser, how does the container find the Helloservlet.class file and execute it http://localhost:8080/firstweb/sayHi?
First the container will find the corresponding folder under WebApps according to the Firstweb name, and then according to the "/sayhi" in the address Find the matching node in the Web. xml file, find the matching node, find the node immediately adjacent to the node, get the name and find the node that is equal to the name, find the same node, search for the node immediately below the node, and then get the class name corresponding to the address, with the help of ClassLoader loading the class file, Creating the object and invoking the service () method, the client sees a running result that matches that address.

405 Causes of errors and solutions

405 This error occurs because the container cannot find the service method to process the request. The following conditions container will be treated as if the service () method is not found
Incorrect service method name, wrong alphabetical order, or case error
The service method parameter types are inconsistent with the criteria, or the order of the parameters is inconsistent with the criteria. Must be httpservletrequest first, then the HttpServletResponse type.
Service method exception, return value type and standard inconsistent, must be thrown servletexception, IOException. The return value type is void.
The workaround for the 405 error is to check that the service method exists and that the signature (method name, parameter, return value, exception type) is consistent with the method in the overridden parent class.

500 causes of errors and solutions

500 error occurs because the requested servlet has an error executing the service method and the program cannot continue running. The following conditions container will be treated as a case of 500 and returned to the client with this error description.
Servlet does not inherit HttpServlet or implement Servlet interface
A write error in the Web. xml file does not match the real package name class name
The code in the Service method throws an exception when it runs
To solve 500 of the method is based on the above three cases of detection, one by one exclusion.

Common errors and workarounds for Web programs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.