Javascript 将Json对象从java脚本传递到java
我不熟悉斯普林斯和阿贾克斯 我的java脚本中有一个动态创建的json对象 我需要使用ajax或normal submit()从java脚本发送这个json对象 如果它是一个字符串,我们有隐藏的输入 据我所知,如果我没有错的话 一个JSON对象,我们无法将其存储在隐藏的 我必须使用java代码接收。 这是我的剧本Javascript 将Json对象从java脚本传递到java,javascript,java,json,ajax,spring-mvc,Javascript,Java,Json,Ajax,Spring Mvc,我不熟悉斯普林斯和阿贾克斯 我的java脚本中有一个动态创建的json对象 我需要使用ajax或normal submit()从java脚本发送这个json对象 如果它是一个字符串,我们有隐藏的输入 据我所知,如果我没有错的话 一个JSON对象,我们无法将其存储在隐藏的 我必须使用java代码接收。 这是我的剧本 $(document).ready(function(){ // click on button submit $("#save_btn").on('click', f
$(document).ready(function(){
// click on button submit
$("#save_btn").on('click', function(){
alert();
// send ajax
$.ajax({
url: 'project_reg_save', // url where to submit the request
type : "POST", // type of action POST || GET
dataType : 'json', // data type
data : $("#reg_form").serialize(), // post data || get data
success : function(result) {
// you can see the result from the console
// tab of the developer tools
console.log(result);
},
error: function(xhr, resp, text) {
console.log(xhr, resp, text);
}
})
});
});
这是我的java代码
@Controller
public class Save {
@RequestMapping("/project_reg_save")
public ModelAndView mymethod(@RequestParam JSONObject obj)//which is not possible {
System.out.println(obj);
return new ModelAndView("Product_reg", "msg", "product Registration");
}
}
一个解决办法是
因此,您可以获得json对象或者尝试将其作为字符串传递,然后使用Java对其进行序列化?它不是请求参数,而是请求正文。尝试将注释更改为
@RequestBody
,并在@RequestMapping