1

j_security_checkログインプロセスを実行するには十分ではないようです。そのため、フォームを j_security_check に送信する代わりに、独自のサーブレットを作成し、プログラムでログインしようとしています。これは機能しますが、制限されたリソースにリダイレクトできません。何が問題なのか誰にも教えてもらえますか? これはprocessRequest私のサーブレットの方法です:-

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            String strUsername = request.getParameter("txtusername");
            String strPassword = request.getParameter("txtpassword");
            if(strUsername == null || strPassword == null || strUsername.equals("") || strPassword.equals(""))
                throw new Exception("Username and/or password missing.");
            request.login(strUsername, strPassword);
            System.out.println("Login succeeded!!");

            if(request.isUserInRole(ROLES.ADMIN.getValue())){//enum
                System.out.println("Found in Admin Role");
                response.sendRedirect("/app/Admin/home.jsf");

            }
            else if (request.isUserInRole(ROLES.GENERAL.getValue()))
                response.sendRedirect("/app/Common/index.jsf");
            else //guard
                throw new Exception("No role for user " + request.getRemoteUser());


        }catch(Exception ex){
            //patch work why there needs to be blogger here?
            System.out.println("Invalid username and/or password!!");
            response.sendRedirect("/app/Common/index.jsf");
        }finally {
            out.close();
        }
    } 

すべて正常に動作し、「Found in Admin Role」というメッセージも表示されますが、認証後も問題があり、リクエストを他のページにリダイレクトできません。

4

2 に答える 2

1

よくわかりませんが、この問題は

https://glassfish.dev.java.net/issues/show_bug.cgi?id=11340

于 2010-03-23T05:20:00.547 に答える
0

それらの行を削除してください、それらはそこに属していません:

    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();

        out.close();

を閉じるとOutputStream、リダイレクトを実行できません。IllegalStateException: Response already committed実際、サーバー ログにが表示されているはずです。

于 2010-03-20T12:37:52.527 に答える