When i deploy my code I get error
Caused by: java.lang.IllegalStateException: Ambiguous mapping found. Cannot map 'programController' bean method
public java.lang.String com.quizapp.beans.controller.panal.ProgramController.editProgram(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
to {[],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}: There is already 'programController' bean method
public java.lang.String com.quizapp.beans.controller.panal.ProgramController.setupProgram(javax.servlet.http.HttpSession,org.springframework.ui.Model) mapped.
Below is my programController class
@Controller
public class ProgramController {
@RequestMapping(name = "/editProgram", method = RequestMethod.GET)
public String editProgram(HttpServletRequest request, HttpServletResponse response) {
if (request.getSession().getAttribute(Constants.LOGGED_IN_USER) != null) {
ProgramEntity program = new ProgramEntity();
if (request.getParameter("id") == null) {// create
program.setType("create");
} else {// edit
program.setType("edit");
program.setCode(request.getParameter("id"));
}
request.setAttribute("programBean", program);
return "editProgram";
} else {
return "redirect:/login";
}
}
@RequestMapping(name = "/program", method = RequestMethod.GET)
public String setupProgram(HttpSession session, Model model) {
if (session.getAttribute(Constants.LOGGED_IN_USER) != null) {
model.addAttribute("programBean", new ProgramEntity());
// if (request.getSession().getAttribute(Constants.LOGGED_IN_USER) != null) {
// request.setAttribute("programBean", new ProgramEntity());
return "viewProgram";
} else {
return "redirect:/login";
}
}
}
When i make the method editProgram as POST then it deploy perfectly. Why is there problem with adding two GET method. There are many similar questions available on StackOverflow but i couldn't find right answer.
Because you are specifying different names
of RequestMapping
and not values
. Currently, value
of both the methods are same ( ""
- empty) which is not allowed. Your URL part of request mapping should be specified in value
and not name
attribute of @RequestMapping
.
Try This:
@Controller
public class ProgramController {
@RequestMapping(value = "/editProgram", method = RequestMethod.GET)
public String editProgram(HttpServletRequest request, HttpServletResponse response) {
if (request.getSession().getAttribute(Constants.LOGGED_IN_USER) != null) {
ProgramEntity program = new ProgramEntity();
if (request.getParameter("id") == null) {// create
program.setType("create");
} else {// edit
program.setType("edit");
program.setCode(request.getParameter("id"));
}
request.setAttribute("programBean", program);
return "editProgram";
} else {
return "redirect:/login";
}
}
@RequestMapping(value= "/program", method = RequestMethod.GET)
public String setupProgram(HttpSession session, Model model) {
if (session.getAttribute(Constants.LOGGED_IN_USER) != null) {
model.addAttribute("programBean", new ProgramEntity());
// if (request.getSession().getAttribute(Constants.LOGGED_IN_USER) != null) {
// request.setAttribute("programBean", new ProgramEntity());
return "viewProgram";
} else {
return "redirect:/login";
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.