i am working on spring mvc where i put mapping on controller class and also on method see the code below:
controller code:
@Controller
@RequestMapping("/role")
public class RoleController {
@Autowired
RoleService roleService;
@GetMapping("/roles")
public String roles(@ModelAttribute Role role, Model model, RedirectView view) {
System.out.println("update e "+model.getAttribute("hasError"));
// System.out.println("role edxists = "+model.getAttribute("role"));
if(model.getAttribute("hasError")==null) {
model.addAttribute("hasError",false);
}
model.addAttribute("roles",roleService.getAllRoles());
if(model.getAttribute("update")!=null && (boolean)model.getAttribute("update")) {
model.addAttribute("update",false);
}
else {
model.addAttribute("role",new Role());
}
return "role-overview";
}
}
i am hitting the url role/roles from home.jsp by clicking a button cole below:
<a href="role/roles" class="text-light" ><div style="height:50px;font-size:30px;" class="container mb-1 col-4 bg-info text-center ">
<p>Role Overview</p>
</div></a>
view resolver code:
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver vr=new InternalResourceViewResolver();
vr.setPrefix("WEB-INF/view/");
vr.setSuffix(".jsp");
return vr;
}
when the controller runs and returns the view name i got this error below:
Type Status Report
Message JSP file [/role/meal-management/WEB-INF/view/role-overview.jsp] not found
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
enter image description here
i understood the problem that when the controller return the view name it concatenate WEB-INF/view?role-overview with controller mapping url role which in result role/WEB-INF/view?role-overview. how can i resolve this issue ?
i just use GetMapping annotation on controller method before this i am using request mapping only
Rtech tricks is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.