JSP study notes

  • 2020-05-19 05:29:51
  • OfStack

1. When declaring variables: < %! int j=1;% > (generate the variable as a member variable of servlet class, multiple clients share one copy) and < % int j=1;% > (only a local variable within a method, one for each client.) during the process of use, try to avoid declaring a variable as a member variable of a class, unless you need to count the number of times an servlet class is accessed. You can't define a method in the latter, you can in the former.

2.java scripts (such as javascript) are executed on the client side, < %...... % > Inside is executed on the server side and the result is passed back to the client.

3.JSP contains instructions:
Static include (usually) : < %@ include file="fileURL"% > The copy of the included file is sent to this location, and then it is compiled and transformed, but only one java and class files are generated. fileURL cannot contain parameters. The included page and the included page access the same request object, which is equivalent to one page.
Dynamic include (not often used) : < jsp: include page="fileURL" flush="true"/ > Parameters can be passed in fileURL; The object that contains the page request is different from the object that contains the page request, but you can take the same parameters (small ones can be request to large ones, and you can add your own parameters). It is converted and compiled when needed, and two java and class files are generated in the background.

4. Two jump modes:

response. sendRedirect (" fileURL "); Jump in the process of the address bar to change, jump into the address of the page after the jump; Two from the server to the client, low efficiency, slow (client request - the server response, turned to the client, the client address bar to change (address can be any legal address as other web sites), automatic submission, request to the server again new address - server after find results feedback to the client shows). This steering does not affect the running of the following code (unless return is added); The page you go to cannot go to the parameter of the previous page; The "/" in URL represents the root path to the domain name

< jsp:forward page="fileURL"/ > When the client requests, the server directly moves to the new address and then directs the result to the client. During the process, the address bar does not change and the transformation is completed inside the server (the address transferred to cannot be an address outside the project). Speed; Although it is a different object, it can take the parameters of the previous page. Statements after forward will not continue; The "/" in URL represents the root path to the webapp project

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

Related articles: