الانتقال إلى المحتوى
View in the app

A better way to browse. Learn more.

مجموعة مستخدمي أوراكل العربية

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Java Sevlet Filter

Featured Replies

بتاريخ:

السلام عليكم

 

انا بحاول اعمل java servlet filter علشان امنع Illegal access علي الابليكاشن . انا بحثت علي الانترنت كتير جدا و كتبت الكود ده لكن المشكله اني لما بكتب ال url بايدي اول مره بيعمل فعلا redirect ل login page لكن لما بكتبه تاني مره بيفتح الصفحه عادي.

 

انا اعتقد ان انا مفروض اعدل الكود بحيث ان انا اعمل setAtrribute في زرار ال login نفسه مش في السيرفليت بس الفكره ان انا مش عارف اعمله من ال backbean و لما عملت servlet ـانيه بتعمل عمليه ال setAttribute مش عارف انادي عليها من ال backbean ازاي ... اتمني تكون المشكله واضحه 

 

 

package Servlets;
 
 
import java.io.IOException;
 
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
public class ServletFilter implements Filter {
    private FilterConfig _filterConfig = null;
 
    public void init(FilterConfig filterConfig) throws ServletException {
        _filterConfig = filterConfig;
    }
 
    public void destroy() {
        _filterConfig = null;
    }
 
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
                                                                                                     ServletException {
        System.out.println("Servlet Start");
        HttpServletRequest servletRequest = (HttpServletRequest)request;
        HttpServletResponse servletResponse = (HttpServletResponse)response;
        servletResponse.setContentType("text/html");
        HttpSession session = servletRequest.getSession();
        String vSessionVariable = (String)session.getAttribute("SessionVariable");
        System.out.println("Session Variable = " + vSessionVariable);
 
        if (servletRequest.getRequestURI().toString().endsWith("/Login.jsf") ||
            servletRequest.getRequestURI().toString().endsWith("/Login") || vSessionVariable != null) {
            System.out.println("Condition Passed");
            session.setAttribute("SessionVariable", "SessionVariable");
            System.out.println("Session Variable = " + vSessionVariable);
            chain.doFilter(servletRequest, servletResponse);
            return;
        } else {
            servletResponse.sendRedirect("faces/Login.jsf");
            return;
        }
    }
}

انضم إلى المناقشة

يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.

زائر
أضف رد على هذا الموضوع...

برجاء الإنتباه

بإستخدامك للموقع فأنت تتعهد بالموافقة على هذه البنود: سياسة الخصوصية

Account

Navigation

البحث

إعداد إشعارات المتصفح الفورية

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.