SpringMVC重定向传参数的实现

https://blog.csdn.net/u011851478/article/details/51872977

在spring的一个controller中要把参数传到页面,只要配置视图解析器,把参数添加到Model中,在页面用el表达式就可以取到。但是,这样使用的是forward方式,浏览器的地址栏是不变的,如果这时候浏览器F5刷新,就会造成表单重复提交的情况。所以,我们可以使用重定向的方式,改变浏览器的地址栏,防止表单因为刷新重复提交。

jsp文件:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>login</title>
</head>
<body>
    
    <form id="form1" action="/demo/user/login" method="post">
        账号:<input type="text" name="name" /></br>
        密码:<input type="password" name="password" /></br>
        <input type="submit" value="submit"/>
        
    </form>
 
</body>
</html>

猜你喜欢

转载自blog.csdn.net/NRlovestudy/article/details/83377060