JSP Study Notes

Source: Internet
Author: User

1. When declaring a variable: <%! Int j = 1; %> (generate the variable into a member variable of the servlet class, multiple clients share one copy) and <% int j = 1; %> when using (only a local variable in a method, each client has one), try to avoid declaring a variable as a member variable of the class, unless you need to count the number of visits to a servlet class. Methods cannot be defined in the latter. The former can.

2. java scripts (such as javascript) are executed on the client. <% ...... The content in %> is executed on the server, and the result is returned to the client.

3. JSP containing commands:
Static inclusion (commonly used): <% @ include file = "fileURL" %> copies the contained files to this location, and then compiles and converts the files, but only one java and class file is generated. fileURL cannot contain parameters, including pages and accessed by included pages are the same request object, which is equivalent to a page, the two must be encoded in the same way;
Dynamic inclusion (not commonly used): <jsp: include page = "fileURL" flush = "true"/> parameters can be passed in fileURL; the object that contains the page and the requested page is different, but the same parameters can be obtained (small parameters can be requested to large parameters, or you can add your own parameters ); it is converted and compiled only when necessary, and two java and class files are generated in the background.

4. Two jump methods:

Response. sendRedirect ("fileURL"); the address bar needs to change during the jump process, and the address of the page after the jump is changed; two round trips from the server to the client are inefficient, slow speed (client request-server response, switch to client, make the client address bar change (the address can be any legal address such as other URLs), automatically submit, request a new address from the server again-the server returns the result to the client after finding it); this kind of steering will not affect the subsequent code running (unless the return is added ); you cannot go to the parameters of the previous page. "/" in the URL indicates the root path of the domain name.

<Jsp: forward page = "fileURL"/> for client requests, the server directly redirects to the new address and then directs the result to the client. The address bar does not change during the process, switch within the server (the address to be transferred cannot be an address other than this project); fast speed; although different objects, you can get the parameters of the previous page; statements after forward are not executed. "/" in the URL indicates the root path of the webapp project.

5. The scope of JSP labels is page, request, session, and application. By default, it is page.
6. Math. floor (cost * 100)/100.0 cost is of the double type. The Math. floor (cost * 100) function is used to return the integer part of cost * 100.

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.