Search code examples
javaformsjspjsp-tags

using content type as JSON in form tag


I am having a page in JSP that needs to submit data to the server. I am just curious that whether by using enctype can we post this data in json format. As i have notice the browser by default encode it into application/x-www-form-urlencoded.


Solution

  • There are two different things here. If you submit a form, changing the enctype is irrelevant, since the data is built by the browser from the form fields (name=value; etc.). So it won't be JSON anyway.

    If you're not using a form but sending post data via an AJAX call, say, you don't have enctype available, you just pass the data you want, in whatever format the server expects.