The path to learning java pain [12] JSON + ajax + Servlet JSON data conversion and transmission, ajaxjson

Source: Internet
Author: User

The path to learning java pain [12] JSON + ajax + Servlet JSON data conversion and transmission, ajaxjson

1. First the client needs to introduce jquery-1.11.1.js

2, followed by javaweb project needs to introduce jar package [commons-beanutils-1.8.0.jar, commons-collections-3.1.jar, commons-lang-2.4.jar, commons-logging-1.1.3.jar, ezmorph-1.0.6.jar]

3. Client js Code

4. servlet server, mapped path CardColl

The above is the entire process. If you have better ideas, you can discuss them together.


The backend uses Servlet to get the JSON from Ajax and then sends it to the backend. How can this problem be solved?

The json file passed to the background is incorrect. You are passing xml.
Json should be: data = {'msg ': {'fromusername': 'erbao', 'tousername': 'me', 'msgtype': 'Hello! '}};
Splice a json string in the background to your success method and parse it with eval (data.
Check your code and you will return "{'result': 1}" in the background. Success Method:
Data = eval (data );
If (data. result = 1 ){}
 
Servlet + ajax + jquery + json

This is because the bean contains the Date Field and the data read from the database is java. SQL. date is assigned to java. util. date, an error occurred when converting to JSONArray; just convert it when the data is queried.
You can also learn how to copy the error message directly to google after an error is reported, so it is easy to find the answer.

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.