获取表单中隐藏字段的价值

时间:2019-05-03 08:08:13

标签: spring-boot hidden-field

这是我的登录表单,其中包含隐藏字段名称“ callbackUrl”。如何获取控制器中此隐藏字段的值?用户的属性是用户名和密码。 callbackUrl不是。

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="/resources/css/bootstrap.min.css" rel="stylesheet">
    <link href="/resources/css/common.css" rel="stylesheet">
<title>Authentication Service</title>
</head>
<body>
<form method="POST" action="/login" modelAttribute="userFormLogin" class="form-signin">
    <h2 class="form-heading">Log in</h2>
    <input name="username" type="text" class="form-control" placeholder="Username"
       autofocus="true"/>
    <input name="password" type="password"  class="form-control" placeholder="Password"/>
    <input name="callbackUrl" type= "hidden" id="callbackUrl">
    <h2>${error}</h2>
    <br/>
    <button class="btn btn-lg btn-primary btn-block" type="submit">Log In</button>
    <h4 class="text-center"><a href="/registration">Create an account</a></h4>
</form>
</body>
<script>
    var url_string = window.location.href; //window.location.href
    var url = new URL(url_string);
    var c = url.searchParams.get("callbackUrl");
    console.log(c);
    document.getElementById("callbackUrl").value = c;
</script>
</html>

1 个答案:

答案 0 :(得分:0)

__init__.py添加到控制器中的方法。

像这样:

@RequestParam("callbackUrl") String callBackUrl