Strange! The parameters in the address bar submitted by post are actually visible.

Source: Internet
Author: User

In a project, the method = "Post" in the form label and the declaration method = "Post" is also displayed in the submitted method, but the address bar parameters are still visible.

The address bar parameters are visible. The biggest drawback is that the website is not secure. Another drawback is that when the address bar parameter is too long, the page cannot run.

Why are the address bar parameters visible? Instead of using method. First, let's take a look at my submission methods.

The code for submitting a function in JS is as follows:

   with(document.forms[0])  {  action="roleAuthoriedManager!getModuleOperateBySystem?roleId="  +document.getElementById("roleId").value  +"&systemId="+document.getElementById("systemId").value  +"&pageNo="+<%=pageModelModule.getPreviousPageNumber()%>          +"&queryString="+document.getElementById("searchById").value          +"&ids="+checkedIds;  method="post";  submit();  }

Seeing the code, do you understand why?

If you understand it, you have a deep understanding of get and post submission. If you are confused, you don't have to worry about it.

First, explain why the address bar parameters are visible.

Because the parameter has been clearly dripped in my action redirection. As long as there are obvious parameters in the action, whether get or post, these parameters will appear in the address bar.

What is the difference between get submission and post submission?

As we all know, get is submitted, and the address bar parameters are visible. While post is submitted, the address bar parameters are invisible. Therefore, post submission is safer than get submission.

There is no error in this sentence. I often say this to others, but this sentence is very vague. Are the parameters visible? Why is the amount still visible when the parameters passed in by action are submitted using post?

The detailed statement is: Get submit, which transmits the name and value of input in the form as parameters. (The name value must be set here. If there is only ID and no name, the address bar will not display its parameters ).

Post submission also submits the name and value of input in the form. However, the address bar does not contain parameters and values in the form.

This is an obvious difference between the two. Of course, the principle of this difference will continue to be differentiated:

Get, the address bar parameters are displayed, so the number of parameters passed is limited. The page cannot run because it is too long. Post has no parameter restrictions. Therefore, there are many inputs in the form. You can consider post.

Sometimes, in special cases, only post can be used for submission. You don't have to worry about this. You just need to check it in time.

After knowing the reasons and differences, how can we solve this problem? The parameters following the action must be passed in. What should we do?

The first method: Based on the essential reasons of get and post, we can think of making the parameter followed by action into an implicit field, so as to pass it as part of the form.

This method is feasible, and most of them are also implemented.

I didn't adopt the first method. Why? Because my parameters do not conform to the first type, the parameters following the action, such as IDS, cannot be used as implicit fields because they are updated from time to time. The parameter cannot be passed after the action. Because the parameter is too long, the page cannot run. The first implicit domain method is not feasible. How can this problem be solved?

The second method is to create a menu based on the parameters following the action at the time of submission, indicating the hidden domain.

In fact, the second type is extended based on the first type, or the hidden domain is used. The submission class is redefined.

Method 2: The JS Code is as follows:

 function submitForm(url,data) {            var eleForm=document.body.appendChild(document.createElement('form')); eleForm.action=url; for(var property in data) {  var hiddenInput=document.createElement('input');  hiddenInput.type='hidden';  hiddenInput.name=property;  hiddenInput.value=data[property];  eleForm.appendChild(hiddenInput); } this.eleForm=eleForm; if(!submitForm._initialized) {  submitForm.prototype.post = function()        {         this.eleForm.method = 'post';         this.eleForm.submit();        };                 submitForm._initialized = true;    } }

Parameter description: URL, that is, Form redirection. Data, that is, the parameter after the action. This is represented by a JSON string.

JSON, full name JavaScript Object Notation, a lightweight data exchange language, mainly used JavaScript to deal with servers. JSON has two expressions.

An object is represented by a name-Value Pair in braces ({}). The expression is name: value. Each pair is separated by a comma.

One is a value sequence table, which is enclosed in [] and contains strings. Each string is separated by a comma.

The first method is commonly used. If you want to learn more about JSON, you can learn it on your own.

Defines the preceding submission method. The submission method is described as follows:

First, the form is defined;

Then the hidden fields in the form are defined.

Pay the parameters following the action to the name and value of the implicit domain.

Then the POST method is reset.

The application is as follows:

 new submitForm('userAuthoriedManager!selectRole',                            {userId:userId.value,     pageNo:'<%=pageModel.getNextPageNumber()%>',     queryString:document.getElementById("searchById").value,     checkedIds:checkedIds}).post();

The parameter passing problem has been solved.

As a matter of fact, understanding is deepened with time and experience. However, every time we record or put our understanding of things in our minds, the practice or problem of one day may be a new understanding. In the end, this kind of understanding is actually an experience. The project experience is so accumulated in 1.1 drops that it will not be discarded because of its small size. It's not a day's work.

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.