There is test method which accepts HttpServletRequest
and HttpServletResponse
. It returns ModelAndView
. Before returing the model and view object the response is being redirected to /xyz . If I omit response.sendRedirect(request.getContextPath() + "/xyz");
line of code then the URL in my browser is localhost:8080/project/abc
however adding that line of code makes the URL in the browser localhost:8080/project/xyz
.
public ModelAndView test(HttpServletRequest request, HttpServletResponse response) {
LOGGER.info("Request for dashboard ");
ModelAndView modelAndView = new ModelAndView();
response.sendRedirect(request.getContextPath() + "/xyz");
modelAndView.setViewName("index");
return modelAndView;
}
Now if I donot set the view name in the above code then it results in an error.
public ModelAndView test(HttpServletRequest request, HttpServletResponse response) {
LOGGER.info("Request for dashboard ");
ModelAndView modelAndView = new ModelAndView();
response.sendRedirect(request.getContextPath() + "/xyz");
return modelAndView;
}
What exactly is happining under covers?
Aucun commentaire:
Enregistrer un commentaire