Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common problems in Java and JSP programming

2025-01-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you "what are the common problems in Java and JSP programming", the content is simple and clear, and I hope it can help you solve your doubts. Let the editor lead you to study and learn what are the common problems in Java and JSP programming.

Java is the general name of Java programming language and Java platform launched by Sun Microsystems in May 1995. JSP is a technical standard for dynamic web pages. JSP technology is a bit similar to ASP technology, it inserts Java program segments (Scriptlet) and JSP tags (tag) into traditional web page HTML files (* .htm, * .html) to form JSP files (* .jsp). The following is an analysis of the problems often encountered in Java and JSP programming.

1. When an object of type String uses the println () method, if the object is null, the null will be printed instead of raising NullPointerException. The problem referenced from this is easy to cause illusion and problems for later manipulation of strings.

two。 NullPointerException exception is thrown mainly because the existence of the object is not verified, which often appears in jsp programming: if (request.getParameter ("username"). Equals ("xxx"), out.println (session.getAttribute ("record")) and so on. The solution to this problem is to make an empty comparison before use:

If (request.getParameter ("username")! = null)

{if if (request.getParameter ("username").

Equals ("xxx"))... }

3. Throw a NumberFormatException exception: the main reason is that the user entered other illegal characters when converting the content submitted by the user to an integer or floating point number. The main way to handle this is to use try/catch blocks to catch this exception where conversion is needed and then prompt the user for legitimate data.

4. Throw a StringIndexOutOfBoundsException exception: the main reason is to use the substring (), charAt (), and other methods of String, which will be thrown if the length of the string is not enough; NullPointerException will also be thrown when the string is null. The solution is to determine the null, determine the length, or convert to a byte array. Given the number of these operations, you can encapsulate them in javabean.

5. The NoClassDefFoundError error is mainly caused by the misplacement of the classpath or class file, which should meet the requirements of the server.

6. The main reason for the java.lang.Error error is that the external resources accessed by the system are not closed, resulting in a large amount of waste of external resources, which may eventually lead to the normal operation of the system; the external resources accessed by the system are closed too many times, and the external system cannot handle them properly; the external resources accessed by the system are abnormal.

The solution is: before accessing the external resource, first check whether the resource (such as the database) can be connected or operated normally; when accessing the external resource, if there is a connection, be sure to close the operation, and only close the operation once; try to share external resources in the same operation, so as to reduce the consumption of resources and improve the execution efficiency of the program.

That's all of the article "what are the common problems in Java and JSP programming?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report