Notebook 002

1、JavaScript SetInterval与setTimeout

      setTimeout(function() {getVerifyCode(term);}, 1000);

      The syntax for setTimeout and setInterval is the same. They both have two parameters, a string of code that will be executed, and an interval in milliseconds after which the code will be executed. However, these two functions are still different. After setInterval executes the code once, after that fixed time interval, it will automatically execute the code repeatedly, while setTimeout only executes the code once. When using a function name as a call handle, it cannot take any parameters.

       Difference: window.setTimeout("function",time);//Set a timeout object, only execute once, no cycle 

                  window.setInterval("function",time);//Set a timeout object, period = 'interaction time'

       Stop: window.clearTimeout(object) clears the setTimeout object that has been set

                  window.clearInterval(object) clears the setInterval object that has been set

       例如:function hello(){   alert("hello"); }

                  var id=window.setTimeout(hello,5000);

                  document.onclick=function(){ window.clearTimeout(id);}     

2. The difference between forward and redirect

      1. From the address bar display

      Forward means that the server requests resources. The server directly accesses the URL of the target address, reads the response content of that URL, and then sends the content to the browser. The browser does not know where the content sent by the server comes from, so it The address bar is still the original address.

      Redirect means that the server sends a status code based on logic, telling the browser to re-request that address. So the address bar displays the new URL.

       2. In terms of data sharing

       forward: The forwarded page and the forwarded page can share the data in the request.

       redirect: data cannot be shared.

       3. From the point of application

       Forward: Generally used when a user logs in, forwarding to the corresponding module according to the role.

       redirect: generally used for returning to the main page and jumping to other websites when users log out and log in.

       4. In terms of efficiency

       forward: high.

       redirect: low.

       There are two implementations in Servlet: 

       forward方式:request.getRequestDispatcher("/somePage.jsp").forward(request, response);

       redirect方式:response.sendRedirect("/somePage.jsp");

       Forward is the internal redirection of the server. After the program receives the request, it is redirected to another program, and the client does not know it. Redirect means that the server sends a status header to the client after receiving the request, and the client will request again. There are two more here. Subsequent network communications. Of course, forward also has shortcomings, that is, if the path of the forward page is a relative path, there will be some problems.

       forward will bring the request state, bean and other information to the next jsp redirect is sent to the client and then request again, so the data will not be retained. Using forward you can use getAttribute() to get the previous jsp bean etc.

       In some cases, for example, you need to jump to a resource on another server, you must use the HttpServletResponse.sendRequest() method.

       Both forward and include are basically forwarded to resources inside the context, and redirect can be redirected to external resources, such as: req.sendRedriect("http://www.mocuai.com");

        Summarize:

        A. Redirect means that the client sends two requests to the server, and also receives two responses, but Forward is only one request and one response. In contrast, Forward has higher performance.

        B.Forward can store the Attribute of the request Scope but Redirect cannot.

        The URL does not change at the same time as C.Forward.

        D.Forward needs to be implemented by a Dispatcher in the Servlet.

        E.Redirect can prevent some unknown consequences caused by client Refresh in some cases (such as continuous deletion)

3. Enter calc in the calculate cmd to open the calculator

4. The difference between cookies and sessions:

      1. The cookie data is stored on the client's browser, and the session data is stored on the server.

      2. The cookie is not very safe. Others can analyze the cookie stored locally and perform cookie deception. Considering the security, the session should be used.

      3. The session will be saved on the server for a certain period of time. When the number of visits increases, it will take up the performance of your server. In order to reduce the performance of the server, you should use cookies.

      4. The data saved by a single cookie cannot exceed 4K. Many browsers limit a site to save a maximum of 20 cookies.

      5. So personal suggestion: store important information such as login information as SESSION, and if you need to keep other information, you can put it in COOKIE.

       The connection between cookies and sessions: sessions work through cookies.

       But cookies can be disabled artificially, so there must be other mechanisms to pass the session id back to the server when cookies are disabled. , A technique that is often used is called URL rewriting, which is to append the session id directly to the URL path. There is also a technique called form hidden fields. That is, the server will automatically modify the form to add a hidden field so that the session id can be passed back to the server when the form is submitted.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326992752&siteId=291194637