I recently started to learn Java Servlet. Today I wrote a small Java Servlet program for website login verification. After I finish writing it, the compilation was successful, however, when I enter the user name and password and jump to the welcome page, something went wrong. In my welcom. in the Java program, I can accept the user name and password on the login page, but I cannot accept the table read from the database, it took me a long time, to find the cause of the error. The problematic statement is as follows:
Pstm = con. prepareStatement ("select * fromuserslimit" + pageSize * (pageNow-1) + ", 3 ");
This statement seems to have no problem ah, good ah, but the problem is in this place: pageSize * (pageNow-1), here I added a bracket, when I wrote this, I thought pageSize * (pageNow-1) and pageSize * (pageNow-1) are the same, no problem. I used to write Java programs in this way, and I didn't see any errors. But today I have planted these brackets. It took me a long time to find errors. At the beginning, I thought this problem was caused by the writing format of the table, but I did not pick a problem on the writing format of the table for a long time, and then I found another row in the row, I think there is no error. At the end of the day, I really collapsed. I only needed to ask for help from my friends on the Internet. My friends on the Internet asked me if I had a problem connecting to the database, so I started to focus on the database program again, so I wondered if I tried
Pstm = con. prepareStatement ("select * fromuserslimit" + pageSize * (pageNow-1) + ", 3 ");
Change to: pstm = con. prepareStatement ("select * fromuserslimit0, 3 ");
Haha, indeed, when I opened the program, my program runs normally, so I think the problem must be out of the pageSize * (pageNow-1) on this, but this pageSize * (pageNow-1) can not see what's wrong with it, when I remove the parentheses outside, ah, the program is normal, although I do not know why the pageSize * (pageNow-1) with more parentheses can not access the database, but I am still very happy, because I always find the problem where ah, you will notice when writing similar programs later.
I will write out the mistakes I made today. For your reference, this can be avoided. This kind of mistake is not easy to see. When you encounter a situation like Java Servlet, pay attention to it, it won't be as dizzy as I am today.
- Future Response Servlet features
- Brief Introduction to Servlet instance running
- Analysis of ServletQueryForConnPool Test
- Tomcat Java Servlet Engine Security Settings
- Jetty-Additional Servlet container Functions