<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