File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed
Ch04_OutputEscapingJSP/src/main/java/de/dominikschadow/webappsecurity/controller Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change 2121import org .slf4j .Logger ;
2222import org .slf4j .LoggerFactory ;
2323import org .springframework .stereotype .Controller ;
24+ import org .springframework .ui .Model ;
25+ import org .springframework .web .bind .annotation .ModelAttribute ;
2426import org .springframework .web .bind .annotation .RequestMapping ;
2527import org .springframework .web .bind .annotation .RequestMethod ;
2628import org .springframework .web .bind .annotation .SessionAttributes ;
27- import org .springframework .web .servlet .ModelAndView ;
2829
2930/**
3031 *
@@ -37,9 +38,11 @@ public class ContactController {
3738 private Logger logger = LoggerFactory .getLogger (getClass ());
3839
3940 @ RequestMapping (value = "/addContact" , method = RequestMethod .POST )
40- public ModelAndView addContact (Contact contact ) {
41+ public String addContact (@ ModelAttribute Contact contact , Model model ) {
4142 logger .info ("Firstname: " + contact .getFirstname () + ", Lastname: " + contact .getLastname ());
4243
43- return new ModelAndView ("contact" , "command" , contact );
44+ model .addAttribute ("contact" , contact );
45+
46+ return "contact" ;
4447 }
4548}
Original file line number Diff line number Diff line change 1919
2020import de .dominikschadow .webappsecurity .domain .Contact ;
2121import org .springframework .stereotype .Controller ;
22+ import org .springframework .ui .Model ;
2223import org .springframework .web .bind .annotation .RequestMapping ;
23- import org .springframework .web .servlet .ModelAndView ;
2424
2525import static org .springframework .web .bind .annotation .RequestMethod .GET ;
2626
3333@ RequestMapping (value = "/" )
3434public class IndexController {
3535 @ RequestMapping (method = GET )
36- public ModelAndView index () {
37- return new ModelAndView ("index" , "command" , new Contact ());
36+ public String index (Model model ) {
37+ model .addAttribute ("contact" , new Contact ());
38+
39+ return "index" ;
3840 }
3941}
You can’t perform that action at this time.
0 commit comments