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";
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. 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";
}
  1. How can we solve this ?

}

A
  1. The application will throw a 500 server error.
  2. 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>
How well did you know this?
1
Not at all
2
3
4
5
Perfectly