有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

基于spring mvc的java返回json字符串xml

如何在点击url后返回json字符串?我点击网址/helloworld/测试。但我得到了这个响应错误404/WEB-INF/jsp/“null”。jsp。我正在使用Spring MVC hibernate。使用Autowired我得到了字符串,但我想要基于xml的。所以我做错了什么。请告诉我怎么做

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    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 org.springframework.web.servlet.mvc.multiaction.MultiActionController;

    import com.google.api.client.json.Json;
    import com.google.gson.Gson;
    public class HelloWorldController extends MultiActionController{

        //@RequestMapping(value="/gDirectory/get_user_names.htm" ,method=RequestMethod.GET)
        public @ResponseBody String add(HttpServletRequest request,
                HttpServletResponse response) throws Exception {

                Gson test = new Gson();
                return test.toJson("null");

            }

            public ModelAndView delete(HttpServletRequest request,
                HttpServletResponse response) throws Exception {

                return new ModelAndView("CustomerPage", "msg","delete() method");

            }

            public ModelAndView update(HttpServletRequest request,
                HttpServletResponse response) throws Exception {

                return new ModelAndView("CustomerPage", "msg","update() method");

            }

            public ModelAndView list(HttpServletRequest request,
                HttpServletResponse response) throws Exception {

                return new ModelAndView("CustomerPage", "msg","list() method");

            }

            public  String testing(HttpServletRequest request,
                    HttpServletResponse response) throws Exception {


                Gson test = new Gson();
                return test.toJson("null");


            }

    }

共 (0) 个答案