Skip to content

Commit d4c00c6

Browse files
committed
Reading HTML Form Data.
1 parent 4932acc commit d4c00c6

File tree

4 files changed

+52
-0
lines changed

4 files changed

+52
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.luv2code.springdemo.mvc;
2+
3+
import org.springframework.stereotype.Controller;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
6+
@Controller
7+
public class HelloWorldController {
8+
9+
// need a controller method to show the initial HTML form
10+
11+
@RequestMapping("/showForm")
12+
public String showForm() {
13+
return "helloworld-form";
14+
}
15+
16+
// need a controller method to process the HTML form
17+
18+
@RequestMapping("/processForm")
19+
public String processForm() {
20+
return "helloworld";
21+
}
22+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Hello World - Input Form</title>
5+
</head>
6+
<body>
7+
<form action="processForm" method="GET">
8+
9+
<input type="text" name="studentName" placeholder="What's your name?" />
10+
<input type="submit" />
11+
12+
</form>
13+
</body>
14+
</html>

web/WEB-INF/view/helloworld.jsp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<body>
5+
6+
Hello World of Spring!
7+
<br><br>
8+
Student name: ${param.studentName}
9+
10+
</body>
11+
12+
</html>

web/WEB-INF/view/main-menu.jsp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33

44
<body>
55
<h2>Spring MVC Demo - Home Page</h2>
6+
7+
<hr>
8+
9+
<a href="showForm">Hello World form</a>
610
</body>
711

812
</html>

0 commit comments

Comments
 (0)