File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed
src/com/luv2code/springdemo/mvc Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change 11package com .luv2code .springdemo .mvc ;
22
33import org .springframework .stereotype .Controller ;
4+ import org .springframework .ui .Model ;
45import org .springframework .web .bind .annotation .RequestMapping ;
6+ import javax .servlet .http .HttpServletRequest ;
57
68@ Controller
79public class HelloWorldController {
@@ -19,4 +21,24 @@ public String showForm() {
1921 public String processForm () {
2022 return "helloworld" ;
2123 }
24+
25+ // new a controller method to read form data and add data to the model
26+
27+ @ RequestMapping ("/processFormVersionTwo" )
28+ public String letsShoutDude (HttpServletRequest request , Model model ) {
29+
30+ // read the request parameter from the HTML form
31+ String name = request .getParameter ("studentName" );
32+
33+ // convert the data to all caps
34+ name = name .toUpperCase ();
35+
36+ // create the message
37+ String result = "Yo! " + name ;
38+
39+ // add message to the model
40+ model .addAttribute ("message" , result );
41+
42+ return "helloworld" ;
43+ }
2244}
Original file line number Diff line number Diff line change 44 <title >Hello World - Input Form</title >
55</head >
66<body >
7- <form action =" processForm " method =" GET" >
7+ <form action =" processFormVersionTwo " method =" GET" >
88
99 <input type =" text" name =" studentName" placeholder =" What's your name?" />
1010 <input type =" submit" />
Original file line number Diff line number Diff line change 44<body >
55
66Hello World of Spring!
7+
78<br ><br >
9+
810Student name: ${ param. studentName }
911
12+ <br ><br >
13+
14+ The message: ${ message }
15+
1016</body >
1117
1218</html >
You can’t perform that action at this time.
0 commit comments