0

Java Web の AccessFilter に問題があります。/main.jspx を呼び出すと、login.jsp にリダイレクトされます。しかし、ログインしようとすると、いくつかのエラーが表示されました

public class AccessFilter implements Filter {

    private FilterConfig filterConfig;

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpSession session = ((HttpServletRequest) request).getSession();
        HttpServletResponse res = (HttpServletResponse) response;
        Client client = (Client) session.getAttribute("client");        
        if (client != null) {
            chain.doFilter(request, response);
        } else {
            RequestDispatcher dispatcher = request.getRequestDispatcher(
                    ConfigurationManager.getInstance().getProperty(ConfigurationManager.LOGIN_PAGE_PATH));
            dispatcher.forward(request, response);
        }
    }

    @Override
    public void destroy() {
        this.filterConfig = null;
    }

}

web.xml:

<filter>
    <filter-name>AccessFilter</filter-name>
    <filter-class>ua.kpi.shop.filter.AccessFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>AccessFilter</filter-name>
    <url-pattern>/jsp/main.jspx</url-pattern>
    <url-pattern>/jsp/pokemons.jspx</url-pattern>
</filter-mapping>

エラー: HTTP ステータス 404 - /PokemonsShop/login.jspx

タイプ ステータス レポート

message /PokemonsShop/login.jspx

説明 要求されたリソースは利用できません。

4

2 に答える 2

0

filterConfig.getServletContext().getRequestDispatcherではなく、絶対パスを使用しrequest-getRequestDispatcherます。それが解決策かどうかはわかりませんが。

于 2012-12-16T23:08:58.790 に答える
0

あなたのメッセージを見て、2 つのことが頭に浮かびました: 1) クライアント オブジェクトが null かどうかを確認しましたか? ログインアクション(メソッド)を実行するときに、クライアントをセッションに正しく設定していない可能性がありますか?2) サーバー エラーでは、「not found /PokemonsShop/login.jspx」と表示されますが、フィルタ マッピングでは /jsp/xxx に言及しています。ログインページが jsp フォルダーの下にあり、(フィルターで) /PokemonsShop/login.jspx にリダイレクトしているためでしょうか。アクセスするには、webapp ルートフォルダーの下にある必要があります。それらの1つが役立つことを願っています

于 2012-12-17T13:12:46.773 に答える