MVC Flashcards
Layers of Spring MVC
-request from web browser
-front controller
-controller
-view template
-back to browser
Components of Spring MVC app
- web pages for UI components
- collection of spring beans
- spring configuration
Another name for front controller
DispatcherServlet
Which part of Spring MVC is given to you already complete?
the front controller (part of the Spring framework)
What does the controller class do?
Business logic - handles requests, store/retrieve data, place data in model.
What does the model do?
contains data, store/retrieve data from backend (DB, web service, etc).
What does the view template do?
displays data from the page the dev creates.
step 1. create controller class process
//define class & annotate with @Controller
public class HomeController(){
…
}
//@Controller inherits from @Component, so it’s a specialized component
Step 2. define controller method
public class HomeController(){
public String showPage(){
…
}
}
Step 3. add request mapping to controller method
public class HomeController(){
@RequestMapping(“/”)
public String showPage(){
…
}
}
Step 4. return view name
public class HomeController(){
@RequestMapping(“/”)
public String showPage(){
//view name
return “main-menu”;
}
}
Step 5. develop view page
<h2>Spring MVC demo home page</h2>
Application flow for reading form data
request mapping (www.website.com/showForm) -> HelloWorldController (shows JSP form) -> request mapping (www.website.com/processForm) -> HelloWorldController -> display JSP confirmation page
What can you put in the spring model?
Anything, really. Strings, objects, info from DB, etc. Your view page (JSP) can access data from the model.
Reading form data using @RequestParam allows you to _______
read form data & automatically bind it to a parameter you’re passing your method