有人可以帮我解决我的重定向问题。我无法使用我的选择选项重定向到特定页面。我已经梳理了大部分的例子,但它似乎没有用。
登录页面
<form class="myform" th:action="@{/login}" th:object="${user}" method="post">
<div th:replace="common/layout :: flash"></div>
<div class="form-group">
<select th:field="*{cert}" class="form-control input-lg" id="selectEl" >
<option value="#">Select a location</option>
<option value="location.htm">Location</option>
<option value="other.htm">Other</option>
</select>
</div>
<div>
<div class="input-group input-group-lg">
<span class="input-group-addon" id="sizing-addon1">@</span>
<input type="text" class="form-control" placeholder="LoginID" th:field="*{username}" aria-describedby="sizing-addon1" />
</div>
</div>
<div class="form-group">
<div class="input-group input-group-lg">
<span class="input-group-addon form-wrapper" id="sizing-addon2">@</span>
<input type="password" class="form-control showpassword" placeholder="Pin" th:field="*{password}" aria-describedby="sizing-addon1" />
<span class="input-group-btn">
<button class="btn btn-default toggle" type="button">Show Pin</button>
</span>
</div>
</div>
<div>
<label>
<input type="checkbox" value="1" id="checkbox" /> <p class="login-caution">I have carefully read all instructions as well as programme requirements in the Admission Brochure and i here my accept any responsibility for any omission(s) or error(s) on my submitted form.</p>
</label>
</div>
<button type="submit" id="btnCheck" class="btn btn-primary btn-lg btn-block">Login</button>
</form>
登录控制器
@RequestMapping(path = "/login", method = RequestMethod.GET)
public String loginForm(Model model, HttpServletRequest request) {
model.addAttribute("user", new User());
String referrer = request.getHeader("Referer");
if(referrer!=null){
request.getSession().setAttribute("url_prior_login", referrer);
}
model.addAttribute("programs", Program.values());
try {
Object flash = request.getSession().getAttribute("flash");
model.addAttribute("flash", flash);
request.getSession().removeAttribute("flash");
} catch (Exception ex) {
// "flash" session attribute must not exist...do nothing and proceed normally
}
return "login";
}
安全配置
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().hasRole("USER")
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.successHandler(loginSuccessHandler())
.failureHandler(loginFailureHandler())
.and()
.logout()
.permitAll()
.logoutSuccessUrl("/login").deleteCookies("JSESSIONID").logoutSuccessUrl("/");
}
public AuthenticationSuccessHandler loginSuccessHandler() {
//return (request, response, authentication) -> response.sendRedirect("/");
return (request, response, authentication)-> {
response.sendRedirect(request.getHeader("url_prior_logins"));
};
}