Small issues encountered when learning Java Servlet

Source: Internet
Author: User

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.

  1. Future Response Servlet features
  2. Brief Introduction to Servlet instance running
  3. Analysis of ServletQueryForConnPool Test
  4. Tomcat Java Servlet Engine Security Settings
  5. Jetty-Additional Servlet container Functions

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.