在Controller中,组装好JSON格式的数据,然后输入到页面,或者通过ajax请求在页面进行解析,都可以做到。

1、Controller  

    /** 
 * JSON DATA TO PAGE VEIW 
 * @param user 
 * @param request 
 * @return 
 * @throws IOException  
 */  
@RequestMapping("/addUser3")  
public void add3(HttpServletRequest request,HttpServletResponse response) throws IOException{  
    response.setContentType("application/json;charset=utf-8");  
    PrintWriter out = response.getWriter();  
    String str = "{username:'残缺的孤独',password:'admin123'}";  
    out.write(str);  
}  

2、请求

请求 http://localhost:8080/TestSpringMVC3/data/addUser3,结果如下:

SpringMVC之Controller传递JSON数据到页面

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-09-16
  • 2021-11-08
  • 2022-12-23
  • 2021-06-30
  • 2021-06-06
猜你喜欢
  • 2021-10-03
  • 2022-02-28
  • 2021-11-01
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
相关资源
相似解决方案