Suggestions for new users to improve JSP technical capabilities

Source: Internet
Author: User
Suggestions for new users to improve JSP technical capabilities 1. How to quickly improve your technical capabilities
Create a project. The assumption is also true.

For example, you want to create a forum, such as csdn. You may encounter many difficulties during the production process.
YourCodeThe structure will change many times. I am talking about the structure, and the code will change more.
When a problem occurs, first go to the search engine to search. I only go to Google. You can determine a bit,

You are definitely not the first person to encounter this problem, or the last one..

Only by thinking, searching, and finally mastering the things is really your own.
I can't figure it out, nor can I find it (because I can't find it, rather than not). I can go to the Forum, QQ or something and ask for help from others.
The problem will also be confined to a certain technical point. After all, you have already thought about it yourself, and you will be enlightened by a little bit of others.
For those who directly asked how to do this function, they basically did not think carefully. Otherwise, he would only ask, who knows where XXX is, how can we achieve the effect of YYY?

In addition,English is indispensableSo many people came to ask for help with exceptions ....

Ii. jsp debugging

It is better to teach fish to fish. It is the right way to master effective debugging methods.

Nullpointerexception
Classnotfoundexception
The occurrence frequency of these two events is too high. If he can take a closer look, the exception information will be pointed out to you in that line, and he will go straight to it.Source codeNo.
Take Tomcat as an example. The JSP file is first translated into a. Java file by Tomcat jspc, a servlet, and then compiled into a. Class file by javac.

Error found

There are two types of error messages
1 Source code error

Copy content to clipboard

Code:

Org. Apache. Jasper. jasperexception: Unable to compile class for JSP:

An error occurred at line: 24 in the JSP file:/viewthread. JSP
syntax error, insert ";" to complete statement
21 :}< br> 22: If (post. getidparent ()> 0) {
23: %>
24:
25: <%
26: return;
27 :}

Stacktrace:
At org. Apache. Jasper. compiler. defaulterrorhandler. javacerror (defaulterrorhandler. Java: 85)
At org. Apache. Jasper. compiler. errordispatcher. javacerror (errordispatcher. Java: 330)
At org. Apache. Jasper. compiler. jdtcompiler. generateclass (jdtcompiler.

You can see that the compilation fails in row 24th. After checking, the <% post. getidparent () %> minus the equal sign <% = post. getidparent () %>

This type of error is easier to find because the error information corresponds to the source code line by line.

2. Running Error

Copy content to clipboard

Code:

HTTP status 500-

--------------------------------------------------------------------------------

Type exception report

Message

Description the server encountered an internal error () that prevented it from fulfilling this request.

Exception

Org. Apache. Jasper. jasperexception
Org. Apache. Jasper. servlet. jspservletwrapper. handlejspexception (jspservletwrapper. Java: 512)
Org. Apache. Jasper. servlet. jspservletwrapper. Service (jspservletwrapper. Java: 395)
Org. Apache. Jasper. servlet. jspservlet. servicejspfile (jspservlet. Java: 314)
Org. Apache. Jasper. servlet. jspservlet. Service (jspservlet. Java: 264)
Javax. servlet. http. httpservlet. Service (httpservlet. Java: 802)

Root Cause

Java. Lang. nullpointerexception
Java. Math. bigdecimal. compareto (bigdecimal. Java: 2406)
Com.goodtp.sales.html. Order. getorderitem (order. Java: 146)
Com.goodtp.sales.html. htmlorder. saveorder (htmlorder. Java: 214)
Org. Apache. jsp. saler. saveorder_jsp. _ jspservice (saveorder_jsp.java: 180)
Org. Apache. Jasper. runtime. httpjspbase. Service (httpjspbase. Java: 97)
Javax. servlet. http. httpservlet. Service (httpservlet. Java: 802)

This error is the most common. Note the following line:
Org. Apache. jsp. saler. saveorder_jsp. _ jspservice (saveorder_jsp.java: 180)

The error is in row 180 of saveorder_jsp.java. How can I find this file?

This file is under the tomcat/Works/directory. You can search for a file under this directory to find the saveorder_jsp.java
After opening the page, find Row 3 and you will be able to see what went wrong.

For eclipse integrated Tomcat debugging, this file is not in the Tomcat directory, but in
Eclipse \ workspace \. Metadata \. plugins \ org. Eclipse. WST. server. Core \ tmp0 \ work

If you cannot find it, you can search for it in full. It usually takes 1-3 minutes.

I found the problem. How can I debug it?

We assume that you have never used the log tool. Now we will use the simplest system. Out. println ().

For example, nullpointerexception indicates that the object of the method called in that row is null,
Int id = order. GETID ();//

You can change it
System. Out. println ("Order =" + order );
Int id = order. GETID ();

Run, you can see on the console
Order = NULL output, so that order is not correctly assigned.

Next, start from here and gradually look for the above to see where order is assigned. For example, find
Order order = orderservice. Find (orderid );

This may be because the order corresponding to orderid does not exist at all. It may be because orderid has taken the wrong parameter.
Change
System. Out. println ("orderid =" + order );
Order order = orderservice. Find (orderid );

Run, the output is
Orderid = 35

Check the database. If Data No. 35 does not exist, you can be sure that the parameter is incorrect. If yes, it must be in the orderservice. Find () method. Search for progress

This is the most basic JSP debugging method.

For Java applications, such as swing, eclipse provides integrated single-step debugging tools, making it easier.

With the accumulation of experience, you will soon find the cause of the problem, and the same error, you will also greatly reduce the chance of re-emergence.

Solution to classnotfoundexception
Classpath. for JSP, the biggest possible reason is that your jar is not put in the correct place, and there are two places for Tomcat.
A) Tomcat \ shared \ lib directory Tomcat 5.5 or Tomcat \ lib directory Tomcat 6
B) The WEB-INF \ lib directory of your application is recommended here.

If you are not sure which jar files are needed, just copy all hibernate with the package. Although not recommended, it is also a temporary solution for beginners.

4. Several Common Problems and Solutions
= Of 1 string, which should be performed using equals ()
2. I forgot Rs. Next () before using resultset ();
3. The database connection is not closed in finally {}.
4. the return value of each method is not determined, resulting inProgramHidden Danger

Source: http://www.java2000.net/viewthread.jsp? Tid = 223

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.