相关疑难解决方法(0)

如何获取所有会话值和名称?

如果我在会话中有值并且我需要在会话中获取所有值,例如

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)
  • 如果我将一组复选框值转换为字符串。我将在 .jsp 中选择的所有值设置为会话对象。我只需要检索保存在上述代码中的 jsp 中的选定值。

java session jsp

7
推荐指数
2
解决办法
2万
查看次数

登录后 Spring Boot 重定向到请求的 URL

我有一个 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)

url-routing spring-security spring-boot

1
推荐指数
1
解决办法
4286
查看次数

标签 统计

java ×1

jsp ×1

session ×1

spring-boot ×1

spring-security ×1

url-routing ×1