html页面中post方式提交数据:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
<!
DOCTYPE
html>
<
html
lang="en">
<
head
>
<
meta
charset="UTF-8">
<
title
>Title</
title
>
</
head
>
<
body
>
<
form
action="http://localhost:8080/test2" method="POST">
<
p
>Name <
input
type = "text" name = "username" /></
p
>
<
p
>password <
input
type = "text" name = "password" /></
p
>
<
p
><
input
type = "submit" value = "submit" /></
p
>
</
form
>
</
body
>
</
html
>
|
控制器:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
package
com.awaimai.web;
import
org.springframework.web.bind.annotation.*;
@RestController
public
class
kzq
{
@RequestMapping
(value =
"/test2"
)
public
String test2(String username,String password)
{
String a = username;
String b = password;
System.out.println(
"username is:"
+username);
System.out.println(
"password is:"
+password);
return
a+b;
}
}
|
web访问:
===================================================
!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="http://localhost:8080/test231" method="POST">
<p>Name <input type = "text" name = "username" /></p>
<p>password <input type = "text" name = "password" /></p>
<p><input type = "submit" value = "submit" /></p>
</form>
</body>
</html>
@RequestMapping(value = "/test231")
public String test2(String username,String password)
{
String a = username;
String b = password;
System.out.println("username is:"+username);
System.out.println("password is:"+password);
return a+"--- ---"+b;
}