前端文件
<form action="welcome1" method="post">
<input type="submit" value="post-请求转发">
</form>
<br>
<br>
<form action="welcome2" method="post">
<input type="submit" value="post-重定向">
</form>
后端控制器类
@Controller
public class SpringMvcController {
@RequestMapping(path = "welcome1",method = RequestMethod.POST)
public String welcome1(){
return "success"; //默认使用请求转发
}
@RequestMapping(path = "welcome2",method = RequestMethod.POST)
public String welcome2(){
return "redirect:success.html"; //使用重定向
}
}
使用@PostMapping注解的方式也一样。
配置类
# 应用名称
spring.application.name=sringmvc-blog
# 应用服务 WEB 访问端口
server.port=8081
# 后缀名
spring.mvc.view.suffix=.html
要跳转的success.html页面
<h1>springMVC 的 post</h1>
运行页面:
结果:
请求转发的方式:
重定向的方式: