An example of a spring MVC JSON transfer

Source: Internet
Author: User

<script type= "Text/javascript" src= "<%=request.getcontextpath ()%>/resources/jquery-1.7.2.min.js" > </script>

The front-end interface calls the resource file to add the Request.getcontextpath () up-down file path, this resources resource (jq.js. ) is placed in the same directory as the Meta-inf Web-inf

The problem with this file is that the Url-parten conflict defined for the spring servlet in Web. XML is changed first to <url-pattern>/hello/*</url-pattern > can do it, but I don't want to start with Hello? Then use the Defaultservlet that activates Tomcat to handle static files.

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/static/*</url-pattern> does not make a mapping of static resource requests.
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>

<body>


</body>

<script type= "Text/javascript" >
$ (document). Ready (function () {
var savedataary=[];
var data1={"UserName": "Test", "Address": "GZ"};
var data2={"UserName": "Ququ", "Address": "GR"};
Savedataary.push (DATA1);
Savedataary.push (DATA2);
$.ajax ({
Type: "POST",
URL: "User/saveuser",
DataType: "JSON",
ContentType: "Application/json",
Data:JSON.stringify (Savedataary),
Success:function (data) {

}
});
});
</script>

Java code in the background as long as you use list<user>.

@RequestMapping (value = "/user/saveuser", method = {Requestmethod.post})
@ResponseBody
public void Saveuser (@RequestBody list<user> users) {
for (User u:users)
{

}
}

An example of a spring MVC JSON transfer

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.