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 6372613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:15:39+00:00 2026-05-25T01:15:39+00:00

I’m using spring-security and jQuery in my application. Main page uses loading content dynamically

  • 0

I’m using spring-security and jQuery in my application. Main page uses loading content dynamically into tabs via Ajax. And all is ok, however sometimes I’ve got the login page inside my tab and if I type credentials I will be redirected to the content page without tabs.

So I’d like to handle this situation. I would like to just write a global handler for all ajax responses that will do window.location.reload() if we need to authenticate.

  • 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-25T01:15:39+00:00Added an answer on May 25, 2026 at 1:15 am

    I’d faced the same problem. Please see the solution I adopted and check whether it is useful for you.

    My log-page used a old model controller instead of spring 3.0 annotation model.

    I registered a global ajax error handler as follows

    jQuery(document).ajaxError(
        function(event, request, ajaxOptions, thrownError) {
            try {
                var result = getJsonObject(request.responseText);//Convert the json reply to json object
                if (result.timeout) {
                    window.location.reload();
                }
            } catch (e) {
                // Ignore this error
            }
        });
    

    Then in my log-in controller, I checks whether the original request was a ajax request or not using the x-requested-with header. If it was a ajax request then I returns a json response saying {"timeout" : true}.

    private boolean isAjaxRequest(HttpServletRequest request) {
        boolean isAjaxRequest = false;
    
        SavedRequest savedRequest = (SavedRequest) request.getSession()
                .getAttribute(
                        DefaultSavedRequest.SPRING_SECURITY_SAVED_REQUEST_KEY);
        if (savedRequest != null) {
            List<String> ajaxHeaderValues = savedRequest
                    .getHeaderValues("x-requested-with");
            for (String value : ajaxHeaderValues) {
                if (StringUtils.equalsIgnoreCase("XMLHttpRequest", value)) {
                    isAjaxRequest = true;
                }
            }
        }
        return isAjaxRequest;
    }
    
    .............   
    .............   
    .............   
    
    if (isAjaxRequest(request)) {
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("timeout", true);
        return new ModelAndView(new JSONView(model));//Returns a json object.
    } else {
        //return login page
    }
    

    Sample implementation of JSONView

    import java.util.List;
    import java.util.Map;
    
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import net.sf.json.JSON;
    import net.sf.json.JSONArray;
    import net.sf.json.JSONObject;
    import net.sf.json.JsonConfig;
    
    import org.springframework.web.servlet.View;
    
    import com.greytip.common.json.CougarJsonConfig;
    
    public class JSONView implements View {
        private JSON jsonObject;
        private JsonConfig jsonConfig;
        private String value;
    
        public JSONView(Object value) {
            this();
            jsonObject = JSONObject.fromObject(value, jsonConfig);
        }
    
        public JSONView(List<?> value) {
            this();
            jsonObject = JSONArray.fromObject(value, jsonConfig);
        }
    
        public JSONView(String value) {
            this();
            this.value = value;
        }
    
        public JSONView() {
            jsonConfig = new JsonConfig();//Your json config
        }
    
        @SuppressWarnings("unchecked")
        public void render(Map map, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
            if (jsonObject != null) {
                jsonObject.write(response.getWriter());
            }
            if (value != null) {
                response.getWriter().write(value);
            }
        }
    
        public String getContentType() {
            return "text/json";
        }
    
    }
    

    This uses the json-lib library to convert the objects to json format.

    Spring 3.0 has very good support for jackson library, you can try to use it.

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm making a simple page using Google Maps API 3. My first. One marker
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.