いくつかのファイルをスキップする(私はそれを変更することはできません):JSFフィルター、私はこのような構造でプロジェクトを持っている
Web Pages
META-INF
WEB-INF
assets (javascript, css and images)
includes (top.xhtml, bottom.xhtml, etc)
templates (master.xhtml)
views
fornecedor
-home.xhtml
-user.xhtml
-login.xhtml
franqueador
-home.xhtml
-user.xhtml
-login.xhtml
Oが理由でフォルダごとにlogin.xhtml
が、私はそれを変更することはできません持って、それがプロジェクトマネージャーに渡されました。
これは私のSessionFilterです:
@WebFilter("/views/*")
public class SessionFilter implements Filter {
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession(false);
LoginController loginController = (LoginController) ((boolean) (session != null) ? session.getAttribute("loginController") : null);
if (!request.getRequestURI().endsWith("/fornecedor/index.xhtml")) {
if (loginController == null || !loginController.getIsLoggedIn()) {
response.sendRedirect(request.getContextPath()
+ "/views/index.xhtml");
} else {
chain.doFilter(req, res);
}
}
}
}
そして、それは動作しませんが、ないhtmlコードと空白のページを返し、私は.html
に.xhtml
を変更すると、それは私にリダイレクトループを与えます。
login.xhtml
ページとindex.xhtml
のすべてをviews
フォルダに保存する必要はありません。私はif
のフィルタをデバッグしましたが、常にfalse
を返します。 BalusC解答後
EDIT
私はこれに来た:
if (!request.getRequestURI().endsWith("/views/index.html")
&& !request.getRequestURI().endsWith("/views/fornecedor/login.html")
&& !request.getRequestURI().endsWith("/views/franqueado/login.html")
&& (loginController == null || !loginController.getIsLoggedIn())) {
response.sendRedirect(request.getContextPath() + "/views/index.html");
} else {
chain.doFilter(req, res);
}
それが動作しているが、別の問題があり、私は10のフォルダを持っている場合、私はこの上でそれらを追加する必要がありますif
声明...私はそれを自動化する必要があります。
こんにちは、あなたの答えに感謝しかし、どのような '@WebFilter(「/ビュー/ *」)について':すべての
login.html
とindex.html
要求のためにそれを一般化するには、単に次のようにありますか?このままにしておきますか? – Gerepこのアノテーションは、フィルタをアプリケーションに登録し、 '/ views/*'と一致するURLパターンで実行できるようにします。これを削除すると、フィルタはまったく登録されないため、まったく実行されません。 – BalusC
私の場合、私の 'views'フォルダ内にいくつかのフォルダがありますが、正しい選択はこのままにしておきます。 @WebFilter( "/ views/*") ' – Gerep