The contenttype set when Ajax passes JSON causes Request.getparameter ("") in Java to receive no data

Source: Internet
Author: User

The ContentType default value set when Ajax passes JSON is application/x-www-form-urlencoded,

When Ajax passes JSON, the ContentType set when it is Application/json or Text/json, in Java, Request.getparameter ("") is not receiving data.

Because in the Java background will think you pass a plain text stream, but not the key value pair, cannot deposit requestmap.

You can read the stream and turn it into JSON to convert to lsit or objects, and use @requestbody annotations in spring.

In a SPRINGMVC environment, @RequestBody receives a string of JSON objects instead of a JSON object. In AJAX requests, however, the JSON object is often passed, and the object can be converted to a string using the Json.stringify (data) method. At the same time the AJAX request also specify datatype: "JSON", ContentType: "Application/json" so you can easily upload an object or list to Java side ...

Reprint: https://www.cnblogs.com/fenglie/articles/5127969.html

The contenttype set when Ajax passes JSON causes Request.getparameter ("") in Java to receive no data

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.