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

  • SEARCH
  • Home
  • 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 6156705
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:39:24+00:00 2026-05-23T20:39:24+00:00

Im using a javascript call from a JSP to login using an AJAX call

  • 0

Im using a javascript call from a JSP to login using an AJAX call and the prototype framework for the server side request, I set up a filter to intercept all requests so that I can either redirect to the login page or proceed.

The problem Im having is that if you type the path into the URL in the browser to go to a different page, theres no way of filtering this before the page loads because its not an AJAX request and in some cases there isnt an HTTPWebRequest until a button is pressed on the page..

What would be the best way to handle this?

Thanks!

  • 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-05-23T20:39:24+00:00Added an answer on May 23, 2026 at 8:39 pm

    I understand that you are not utilizing the Java EE provided container managed authentication. It would namely take this automatically into account when properly configured.

    With a homegrown authentication system, the normal practice is to put the logged-in user as an attribute in the session scope so that the remnant of your code can intercept on that, so also the servlet filters.

    Assuming that your login method look like this:

    User user = userService.find(username, password);
    
    if (user != null) {
        request.getSession().setAttribute("user", user);
    }
    
    // ...
    

    Then you could just do as follows in a 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);
    
        if (session == null || session.getAttribute("user") == null) {
            response.sendRedirect("login.jsp"); // No logged-in user found, so redirect to login page.
        } else {
            chain.doFilter(req, res); // Logged-in user found, so just continue request.
        }
    }
    

    Map this filter on an URL pattern which covers the secured pages, e.g. /app/* or something.

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

Sidebar

Related Questions

I am trying to call a Sample API from my JSP using jQuery Ajax,
I call a javascript function from a textbox by using OnKeyPress=clickSearchButton() Here is my
I am trying to call javascript method from an Applet using netscapte.java.JSObject . in
How we can call webservice from html page using javascript
I'm using getAppletContext().showDocument(new URL(javascript: + command)); to call javascript from applet. But sometimes in
I'm trying to call an ASP.NET .asmx webservice, from javascript, using other than the
I am using a javascript var to control the running of an ajax call.
I'm using a Javascript call to dynamically remove a field from a form. My
I am using ExtrernalInterface.call(javascript_function, args); to call javascript functions from Flex. But this fails
Is there any way to call from javascript to actionscript, not using JSON object.

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.