Ch10: Controllers and Routing Flashcards

1
Q

Define request

A

In exchange of data between client and server, the client sends the request to a specific URL

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Define response

A

In the exchange of data between client and server, the response is a message returned by the server

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

@Controller

A

Annotation designating given class as a controller

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

@GetMapping(“pathname”)

A

Designates controller action. If GET request made to this path, the method will be called

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Use a ____ annotation any time controller needs to respond to requests

A

Mapping

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

@RequestMapping

A

Can handle more than one method (ex: GET and POST). Can be applied at class level to designate base path for all methods in class

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

It’s a best practice to place all controller classes in their own _____

A

subpackage (note: pkgs are lowercase in Java)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why are routes important?

A

Help determine which requests get sent to which controller

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Define query string

A

Extro info included at end of URL (key=value&key=value)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Dynamic vs Static response

A

Static - requests to same path will always return the same response.
Dynamic - response will change based on data sent in the request

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

@RequestParam

A

Annotation used before argument in a controller method. Lets handler method know to look for a query string

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

@PathVariable

A

Annotation used before argument in a controller method. Lets handler method know to look for a path variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Describe how you would redirect a user

A

Remove @ResponseBody annotation (if any) and return redirect:/DESIREDPATH

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does action function in the following form tag?

A

Action specifies the path the form will be submitted at

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the default method of a form tag

A

GET

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How would you set up a controller method to handle both POST and GET requests in Spring

A

Use the @RequestMapping annotation.

@RequestMapping(method = {RequestMethod.GET, RequestMethod.POST}, value = “examplePath”)

17
Q

How do you associate a form field with a request method parameter?

A

Make the input name parameter the same as the request parameter name.

Example:

””

public String hello(@RequestParam String coder) {
return “Hello, “ + coder + “!”;
}