Spring boot webapp with ModelAndView
ModelAndView is used to add data and view name.
HttpServletRequest is used in method parameter to get hold on request object public String home(HttpServletRequest req)
String name=req.getParameter("name") //If the browser/client request with ?name="Dhruv"
get the session from request object like below HttpSession session=req.getSession();
set the session attrubute, so that we can fetch from jsp. session.setAttribute("name", name);
public String Home(String name, HttpSession session)
session.setAttribute("name", name); return "Home" //Provided you have added prefix and suffix keys to application.properties file
Use ModelAndView to set "name" and return "Home"
public ModelAndView(String name) ModelAndView mv=new ModelAndView() mv.setObject("name",name) mv.setViewName("Home") //added prefix and suffix to the .properties file return mv
@RequestParam("name") This will enable to use it inside method parameter, So that we can refer the request parameter that is used at client like below
public ModelAndView Home(@RequestParam("name") String myName) mv.addObject("name",myName)