Home>

I encountered a problem while making a progress bar today.I stored a counter in the session,When crawling a piece of data, this value is +1, and then the foreground gets this value every 3s,But the problem came out,Below ff, the values ​​obtained are all normal,But the life and death under ie are the previous values,Only when you reopen the page can you get the latest session value:

Here is the code of my probar.jsp:

<%@page language="java" import="java.util. *" Pageencoding="utf-"%>
<%
string path=request.getcontextpath ();
string basepath=request.getscheme () + "://" + request.getservername () + ":" + request.getserverport () + path + "/";
%>
<script type="text/javascript" src="<%= path%>/js/jquery.js"></script>
<script type="text/javascript" src="<%= path%>/js/jquery.progressbar.min.js"></script>
<script type="text/javascript">
function createxmlhttprequest () {
  var xmlhttp;
  if (window.activexobject) {
   xmlhttp=new activexobject ("microsoft.xmlhttp");
  } else {
   xmlhttp=new xmlhttprequest ();
  }
  return xmlhttp;
 }
 function btn_click () {
  var xmlhttp;
  xmlhttp=createxmlhttprequest ();
  xmlhttp.onreadystatechange=processor;
  //xmlhttp.open("get ","/jbbs/servlet/controlcrawl?method=getinforsize ", true);
  xmlhttp.open ("post", "/jbbs/servlet/controlcrawl?method=getinforsize", true);
  xmlhttp.send (null);
  function processor () {
   .......
  }
 }
 var action=setinterval ("btn_click ();",);
 </script>
<span>Crawl progress:</span><br />
<div></div>

Later, it was normal to change get to post.

ps:get and post about http

http defines different methods for interacting with the server,There are four basic methods, namely get, post, put, delete. The full name of URL is a resource descriptor,We can think of it like this:a url address, which is used to describe a resource on the network,And get, post, put, delete in http correspond to the check of this resource,Modify, add, delete 4 operations. At this point, everyone should have a general understanding.get is generally used to get/query resource information,The post is generally used to update resource information.

1. According to the http specification, get is used to obtain information,And it should be safe and idempotent.

(1). The so-called security means that the operation is used to obtain information rather than modify information.in other words,Get requests should generally not have side effects.In other words, it is just to obtain resource information,Just like a database query,Does not modify,Increase data,Does not affect the state of the resource.

* Note:The meaning of security here refers only to non-modified information.

(2). Idempotent means that multiple requests for the same URL should return the same result.

Idepotent (idempotent, idempotence) is a mathematical or computer science concept,Common in abstract algebra.

There are several definitions of idempotency:

For monocular operations,If the result of an operation performed multiple times for all the numbers in the range is the same as the result of one operation performed,Then we call the operation idempotent.For example, absolute value operation is an example.In real numbers,There is abs (a)=abs (abs (a)).

For binocular operations,Requires that when the two values ​​participating in the operation are equal,If the result of the operation is equal to the two values ​​participating in the operation,The operation is called idempotent,As a function of the maximum of two numbers,There are idempotent in real numbers,That is max (x, x)=x.

But in practical applications,The above two rules are not so strict.Example of citing someone else's article:For example, the front page of a news site is constantly updated.Although the second request will return a different batch of news,The operation is still considered safe and idempotent,Because it always returns the current news.Basically,If the goal is when a user opens a link,He can be sure from his point of view that no resources have changed.

2. According to the http specification, post indicates a request that may modify a resource on the server.

Continue to quote the above example:Let ’s take the website as an example.Readers' own comments on the news should be implemented through posts, because the resources of the site are different after the comments are submitted,Or the resource has been modified.

But when it ’s actually done,Many people do not follow the http specification.There are many reasons for this problem,For example:

1. Many people are greedy and convenient,Get was used to update the resource, because the post must go to the form, which will be a bit more troublesome.

2. Increase in resources,Delete, change, and check operations can actually be done through get/post, without using put and delete.

3. The other is,The early designers of web mvc frameworks did not consciously treat URLs as abstract resources for their design and design.Therefore, a more serious problem is that the traditional web mvc framework basically only supports the two http methods of get and post, but does not support the put and delete methods.

* About mvc:

mvc originally existed in the desktop program,m is the data model,v refers to the user interface,c is the controller.The purpose of using mvc is to separate the implementation code of m and v,So that the same program can use different expressions.

The above 3 points typically describe the old-fashioned style (without strict adherence to the http specification). With the development of the architecture,Now there is rest (representationalstate transfer), a new style that supports the http specification,Not much to say here,You can refer to "restful web services".

Look at the difference between get and post from the surface:

(1). The first is "the data submitted by the get method can only be up to 1024 bytes", because get submits data through the url,Then the amount of data that get can submit is directly related to the length of the url.In fact, there is no problem with the upper limit of parameters in URLs.The http protocol specification does not set a limit on the URL length.This limitation is a limitation imposed by specific browsers and servers.The IE limit on URL length is 2083 bytes (2k + 35). For other browsers,Such as netscape, firefox, etc., there is no theoretical length limit,Its limitation depends on the support of the operating system.Note that the limitation is the entire url length, not just the length of your parameter value data.

(2) .In theory,Posts have no size limit.The http protocol specification also does not impose a size limit.It is inaccurate to say that "the size of post data is limited to 80k/100k",Post data is unlimited.What is limiting is the processing power of the server's handlers.

For asp programs, the request object has a 100k data length limit when processing each form field.But if you use request.binaryread there is no such limitation.

Extending from this,For iis 6.0, Microsoft for security reasons,Increased restrictions.

We also need to pay attention to:

1) .iis 6.0 defaults the maximum amount of asp post data to 200kb, and each form field limit is 100kb.

2) .iis 6.0 default maximum upload file size is 4mb.

3) .iis 6.0 default maximum request header is 16kb.

There were no such restrictions before iis 6.0.

So the above 80k and 100k may be just the default values ​​(note:I have not confirmed the parameters of iis4 and iis5), but they can definitely be set by yourself.Since the default values ​​of these parameters are different for each version of IIS,For details, please refer to the relevant IIS configuration document.

3. In ASP, the server uses request.querystring to get the get request parameters and request.form to get the post request parameters.

In jsp, use request.getparameter (\ "xxxx \") to obtain. Although jsp also has request.getquerystring () method, it is more troublesome to useFor example:pass a test.jsp?name=hyddd&password=hyddd, use request.getquerystring () and get:name=hyddd&password=hyddd In PHP, you can use $_get and $_post to get the data in get and post respectively.And $_request can get the data in the two requests of get and post.It is worth noting thatThere are hidden dangers when using request in jsp and $_request in php.I will write a summary of this article next time.

4.post is more secure than get.

Note:The security mentioned here is not the same as the "security" mentioned in the get above.The meaning of "security" above is just not to modify the data, and the meaning of security here is the meaning of true security, such as:submit data through get,The username and password will appear in clear text on the url, because (1) the login page may be cached by the browser, (2) other people view the browser's history,Then others can get your account and password,In addition,Submitting data using get may also cause cross-site request forgery attacks.

in conclusion,get is a request for data from the server.A post is a request to submit data to the server.In the form, the method defaults to "get". Essentially, get and post are just different sending mechanisms.Not one for one!

The above is the solution to the inconsistent value of the ajax access changing session that we shared with you, and the difference between the get and post in the http protocol. I hope it is useful for everyone.For more information on ajax session inconsistencies,Stay tuned for this site.

  • Previous Method to get uploaded image information (temporary save path, name, size) through js and then pass it to the backend through aj
  • Next Collect and sort 17 common regular expressions in ASPNET