Output message is not getting displayed when @ModelAttribute is used with @ControllerAdvice in Spring MVC

109 Views Asked by At

I am trying to add ModelAttribute value to different pages within the same application with the help of ControllerAdvice but output message is not getting displayed on the jsp pages.

ServicesController.java

package com.test;     
@Controller
public class ServicesController {
@RequestMapping("/serviceUser") 
public String dis() {
return "input";
}
}

ProductsController.java

package com.test;     
@Controller
public class ProductsController {
@RequestMapping("/products")
public ModelAndView display()
{
ModelAndView m=new ModelAndView("output");
return m;
}
}

GlobalAdviceHandler.java

package com.test;     
@ControllerAdvice 
public class GlobalAdviceHandler {
@ModelAttribute 
public void show(Model model) {
model.addAttribute("msg", "hello world");
}
}

input.jsp

<body>
<p>Services </p>
${msg}
</body>

output.jsp

   <body>
   <p>Products </p>
    ${msg}
    </body>

Thank you in advance!!

0

There are 0 best solutions below