Home  >  Article  >  Web Front-end  >  How Jquery+ajax+springMVC returns json

How Jquery+ajax+springMVC returns json

一个新手
一个新手Original
2017-09-19 10:44:311277browse

JSP page:

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>



	
	登录验证
  	
  	

欢迎登录

用户名:
密 码:
用户名:

Backend control class:

package com.login.control;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONObject;
import com.login.bean.Users;
import com.login.service.UsersService;

/**
 * 用户控制类
 * @author
 *
 */
@Controller
public class UsersControl {
	
	@RequestMapping(value="ajax1.action",method= RequestMethod.POST)    	@ResponseBody
	public Object ajax1(HttpServletRequest request){
		System.out.println("进入控制类");
		JSONObject json = new JSONObject();
		String ms = "ajax测试1成功!哈哈!";
		json.put("ms", ms);
		System.out.println("出控制类");
		return json;
	}
}

You must add these two sentences to return json Value

@RequestMapping(value="ajax1.action",method= RequestMethod.POST)
@ResponseBody

The above is the detailed content of How Jquery+ajax+springMVC returns json. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn