Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8703051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:47:34+00:00 2026-06-13T02:47:34+00:00

I have already visited Java FilterImplementation for session checking link, which says about Spring

  • 0

I have already visited Java FilterImplementation for session checking link, which says about Spring security. I did not get the help i need.

After applying filter login.jsp is unable to load CSS and images.

I am trying simple example providing filter in web.xml and applying the filter on pages other than login.jsp.
Web.xml file is :

<filter>
    <filter-name>struts2</filter-name>
    <filter-class>
         org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
</filter>
<filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
 <filter>
 <filter-name>AuthenticationFilter2</filter-name>
 <filter-class>filter.AuthorizationFilter2</filter-class>
 <init-param>
    <param-name>avoid-urls</param-name>
    <param-value>login.jsp</param-value>
 </init-param>`
 <filter>

And the filter class is :

    private ArrayList<String> urlList;

public void destroy() {
    // TODO Auto-generated method stub
    System.out.println("authorization filter2 destroy method....");
}




public void doFilter(ServletRequest req, ServletResponse res,
        FilterChain chain) throws IOException, ServletException {

    System.out.println("authorization filter2 doFilter method....");

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    String url = request.getServletPath();

    System.out.println("ppp:"+request.getRequestURL());

    System.out.println("url is :"+url);

    boolean allowedRequest = false;

    System.out.println("url list is :"+urlList);

    if(urlList.contains(url.substring(1))) {
        allowedRequest = true;
    }
    System.out.println("request allowed....."+allowedRequest);     
    if (!allowedRequest) {

        Map session = ActionContext.getContext().getSession();

        /*HttpSession session = request.getSession(false);*/
       /* if (null == session) {
            response.sendRedirect("login.jsp");
        }*/

        System.out.println("session contains login :"+session.containsKey("login"));



        if(!session.containsKey("login")){
            response.sendRedirect("login.jsp");
        }

    }

    chain.doFilter(req, res);
}

public void init(FilterConfig config) throws ServletException {
    System.out.println("authorization filter2 init method....");
    String urls = config.getInitParameter("avoid-urls");
    StringTokenizer token = new StringTokenizer(urls, ",");

    urlList = new ArrayList<String>();

    while (token.hasMoreTokens()) {
        urlList.add(token.nextToken());

    }
}

Login page contains css and images as per the requirement.

Please help me out. Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T02:47:35+00:00Added an answer on June 13, 2026 at 2:47 am
    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {
    
    
        String uri = ((HttpServletRequest)request).getRequestURI();
    
        @SuppressWarnings("rawtypes")
        Map session = ActionContext.getContext().getSession();
    
        if ( uri.indexOf("/css") > 0){
            chain.doFilter(request, response);
        }
        else if( uri.indexOf("/images") > 0){
            chain.doFilter(request, response);
        }
        else if( uri.indexOf("/js") > 0){
            chain.doFilter(request, response);
        }
        else if (session.containsKey("login")) {
            chain.doFilter(request, response);
        }
        else {
            ((HttpServletResponse)response).sendRedirect(((HttpServletRequest)request).getContextPath() + "/login?authentication=failed");
        }
    }
    

    put this block of code in your action class , it works.
    Thank you all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have already surveyed SO for an answer, and could not find an appropriate
I have already read Josh Smiths article about binding commands to view model using
How can I apply a font color only to hyperlinks which have already been
I have already visited this thread iPhone + In App purchase testing but the
I have already pushed all the changes to the server. Here is the order
I have already download and install this package to support HTML5 input type http://support.microsoft.com/kb/2468871
I have already googled and searched stackoverflow but I can find nothing related to
I have already tried multiple ways. defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ORGANIZATIONNAME=YourNameHere;}' Also i've tried
I have already created my application on web socket with ASP.net 4.0. I just
I have already read some posts, but no one helped me with my problem.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.