How do you set up dispatcher servlet servlet servlet

Info icon This preview shows pages 92–108. Sign up to view the full content.

How do you set up Dispatcher Servlet?
Image of page 92

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

<servlet> <servlet-name> dispatcher </servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherSer <init-param> <param-name> contextConfigLocation </param-name> <param-value> /WEB-INF/todo-servlet.xml </param-value> </init-param> <load-on-startup> 1 </load-on-startup> </servlet> <servlet-mapping> <servlet-name> dispatcher </servlet-name> <url-pattern> / </url-pattern> </servlet-mapping>
Image of page 93
Questions What is a form backing object? How is validation done using Spring MVC? What is BindingResult? How do you map validation results to your view? What are Spring Form Tags?
Image of page 94

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Show New Todo Page @RequestMapping (value = "/add-todo" , method = RequestMethod.GET) public String showTodoPage (ModelMap model) { model.addAttribute( "todo" , new Todo(0, retrieveLoggedinUserName(), "" , new Date(), false )); return "todo" ; }
Image of page 95
todo.jsp <form:form method= "post" commandName= "todo" > <fieldset> <form:label path= "desc" >Description</form:label> <form:input path= "desc" type= "text" /> <form:errors path= "desc" /> </fieldset> <fieldset> <form:label path= "targetDate" >Target Date</form:label> <form:input path= "targetDate" type= "text" /> <form:errors path= "targetDate" /> </fieldset> <input type= "submit" value= "Submit" /> </form:form>
Image of page 96

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Add Todo @RequestMapping (value = "/add-todo" , method = RequestMethod.PO public String addTodo (ModelMap model, @Valid Todo todo, BindingResult result) { if (result.hasErrors()) { return "todo" ; } service.addTodo(retrieveLoggedinUserName(), todo.getDesc(), false ); model.clear(); return "redirect:list-todos" ; }
Image of page 97
Todo.java public class Todo { private int id; private String user; @Size (min = 6, message = "Enter atleast 6 characters" ) private String desc;
Image of page 98

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Questions What is a Path Variable? What is a Model Attribute? What is a Session Attribute?
Image of page 99
Path Variable @RequestMapping (value = "/todos/{id}" ) public Todo retrieveTodo (@PathVariable int id) { return service.retrieveTodo(id); }
Image of page 100

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

@ModelAttribute public void addAttributes (Model model) { model.addAttribute( "options" , Arrays.asList( "Option 1" , "Option 2" , "Option 3" )); }
Image of page 101
Model Attribute Indicates the purpose of that method is to add one or more model attributes. Invoked before @RequestMapping methods. Used to fill the model with commonly needed attributes Drop down values for form
Image of page 102

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

@SessionAttributes List the names of model attributes which should be transparently stored in the session or some conversational storage. @SessionAttributes ( "name" ) public class TodoController {
Image of page 103
Questions What is a init binder? How do you set default date format with Spring?
Image of page 104

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

@InitBinder protected void initBinder (WebDataBinder binder) { SimpleDateFormat dateFormat = new SimpleDateFormat( "dd/MM/ binder.registerCustomEditor(Date.class, new CustomDateEdit dateFormat, false )); }
Image of page 105
Questions How do you implement common logic for Controllers in Spring MVC? What is a Controller Advice? What is @ExceptionHandler?
Image of page 106

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

Questions How to handle exceptions for web applications?
Image of page 107
Image of page 108
This is the end of the preview. Sign up to access the rest of the document.
  • Spring '18
  • LN Rao
  • public class, Spring Framework, Spring Boot, Spring Security

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern