Section 13 Flashcards
1
Q
@RequestMapping(“/process-formV3”)
public String getProcessFormV2(HttpServletRequest request, Model model) {
String name = request.getParameter(“student”);
name = "Yo! " + name.toUpperCase(); model.addAttribute("message", name); return "process-form"; }
In this method we get the parameter value using request.getParameter but there is a shortcut in doing this, how ?
A
@RequestMapping(“/process-formV3”)
public String getProcessFormV2(@RequestParam(“student”) String name, Model model) {
name = "Yo! " + name.toUpperCase(); model.addAttribute("message", name); return "process-form"; }
2
Q
- What happens if we have the same /form RequestMapping on 2 Controllers like this:
//FormController @Controller public class FormController {
@RequestMapping("/form") public String showForm() { return "form"; }
//SillyController @Controller public class SillyController {
@RequestMapping("/form") public String showForm() { return "silly"; }
- How can we solve this ?
}
A
- The application will throw a 500 server error.
- We need to change de @RequestMapping of the parent controller ( FormController) like this:
@Controller
@RequestMapping(“/hello”)
public class FormController {
@RequestMapping("/form") public String showForm() { return "form"; }
This should be also modified in //home.jsp file
<h1>Home</h1> <a href="hello/form">Go to form</a>