Six common problems for Java and JSP Programming

Source: Internet
Author: User

1. when the println () method is used for objects of the string type, if the object is null, null is printed instead of nullpointerexception, which may lead to the illusion of reference, subsequent operations on strings may cause problems.

2. nullpointerexception is thrown because the object existence is not verified. In JSP programming, if (request. getparameter ("username "). equals ("XXX"), out. println (Session. getattribute ("record. The solution to this problem is to compare the null values before use:

If (request. getparameter ("username ")! = NULL)
{If (request. getparameter ("username ").
Equals ("XXX "))...}

3. numberformatexception: The main cause is that the user inputs other illegal characters when converting the content submitted by the user to an integer or floating point number. The main method of processing is to capture this exception by using try/catch blocks where the conversion is needed, and then prompt the user to enter valid data.

4. stringindexoutofboundsexception exception: the main cause is that the string substring (), charat () and other methods are used. If the string length is insufficient, this exception is thrown; when the string is null, nullpointerexception is also thrown. The solution is to determine the length or convert it to a byte array. Many of these operations can be encapsulated into a JavaBean.

5. The noclassdeffounderror error is caused mainly because the class path or class file is placed incorrectly. The class file should be placed in line with the server's requirements.

6. raise Java. lang. error: The main cause is that the system accesses external resources and does not close the operation, resulting in a large amount of waste of external resources, which may cause the system to fail to run normally; too many times have been disabled for external resources accessed by the system, and the external system cannot be properly processed; external resources accessed by the system may experience exceptions.

The solution is: before accessing an external resource, first check whether the resource (such as a database) can be normally connected or operated. when accessing an external resource, you must disable the connection, only one close operation is performed. Try to share external resources in the same operation to reduce resource consumption and improveProgramExecution efficiency.

Related Article

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.