Suppose there is an index.html , it is called using the controller:

@RequestMapping(value = "/index", method = RequestMethod.GET) public ModelAndView getIndex() { ModelAndView mav = new ModelAndView(); mav.setViewName("index"); return mav; } 

After downloading this page, let's say I have a button there when I click on it, the method is called:

 <script type="text/javascript"> function getPage() { $.ajax({ type: "GET", url: "getPage", success: function (data) { $("#pageContainer").html(data); } }); } </script> 

Next, the Ajax request calls another controller of mine:

 @RequestMapping(value = "/getPage", method = RequestMethod.GET) public ModelAndView getPage() { ModelAndView mav = new ModelAndView(); mav.setViewName("test/page"); return mav; } 

But the getPage () controller returns the whole html / jsp document in data. How can I rewrite the getPage () controller so that it does not return the entire page file but the necessary part of it?

  • Add to the question the code of the page "test / page", and indicate which part you want to return. - MrFylypenko
  • Any html code you see fit. - Dima_Brijatov
  • one
    Then delete the extra code on the page, you only need to leave the contents of the body tag, and remove the tag itself. - MrFylypenko
  • Thanks, all worked well. - Dima_Brijatov
  • Added as an answer, mark as correct - MrFylypenko

1 answer 1

If you have such a jsp page:

 <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title></title> </head> <body> <div>Содержимое страницы</div> <div>Еще данные</div> </body> </html> 

then remove the extra code from it, and leave the contents of the body tag to make it:

 <%@ page contentType="text/html;charset=UTF-8" language="java" %> <div>Содержимое страницы</div> <div>Еще данные</div>