如果我在会话中有值并且我需要在会话中获取所有值,例如
String[] name = request.getParameterValues("values");
HttpSession session = request.getSession();
for(String temp:name)
{
if(temp.equalsIgnoreCase("a"))
{
session.setAttribute("a", temp);
out.println("a is Running<br>");
}
if(temp.equalsIgnoreCase("b"))
{
session.setAttribute("b", temp);
out.println("b is Running<br>");
}
if(temp.equalsIgnoreCase("c"))
{
session.setAttribute("c", temp);
out.println("c is Running<br>");
}
if(temp.equalsIgnoreCase("d"))
{
session.setAttribute("d", temp);
out.println("d is Running<br>");
}
if(temp.equalsIgnoreCase("e"))
{
session.setAttribute("e", temp);
out.println("e is Running<br>");
}
if(temp.equalsIgnoreCase("f"))
{
session.setAttribute("f", temp);
out.println("f is Running<br>");
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个 Spring Boot UI 应用程序。我试图在登录后将用户重定向到最初请求的 URL。
当用户请求http://www.example.com/myapp/user/22 时,应用程序恰当地重定向到http://www.example.com/myapp/login。用户登录后,应用程序将重定向到http://www.example.com/myapp/dashboard。我希望应用程序重定向到http://www.example.com/myapp/user/22。
我浏览了几个链接,觉得我有一个正确的配置,但是重定向没有按预期工作。
我的安全配置是
public class SecurityConfig extends WebSecurityConfigurerAdapter {
.....
....
@Autowired
private MyAuthenticationSuccessHandler authenticationSuccessHandler;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.
authorizeRequests()
.antMatchers("/user/**").authenticated()
.and().csrf().disable().formLogin()
.successHandler(authenticationSuccessHandler)
......
Run Code Online (Sandbox Code Playgroud)
我的成功处理程序是
@Component
public class MyAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler {
...
public MyAuthenticationSuccessHandler() {
super();
this.setDefaultTargetUrl("/myapp/dashboard");
this.setUseReferer(true);
}
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
Authentication authentication) throws IOException, ServletException {
//Do something ..........
........
.........
super.onAuthenticationSuccess(request, response, …Run Code Online (Sandbox Code Playgroud)