Search code examples
javajspservletsweb-applicationsstripes

Why doesn't forwardResolution redirect?


I'm new to Stripes and I'm trying to do like this: pass data from JSP1 using Ajax to the actionBean2 which belongs to JSP2 and then display the data on JSP2.

I do like this because JSP2 provides common interface for everything, and I want to redirect the user to JSP2 so that he/she could see the items that were selected in JSP1 using the standard interface of JSP2. So, the problem occurs when I'm trying to pass the data from ActionBean2 to JSP2. Even though my return statement of actionBean2 looks like this:

return new ForwardResolution("/jsp2.jsp"); 

It actually doesn't redirect me from JSP1 to JSP2. RedirectResolution doesn't work as well. I see the AJAX request from JSP1 being sent, the event handler in ActionBean2 receives it but doesn't redirect me from the JSP1. JSP1 even gets GET request for JSP2 url, but still the page doesn't reload. So, it looks like even though I'm in ActionBean2, it still uses JSP1.

My question is - should ForwardResolution redirect me to another page immediately (and reload the browser page)? And also - it my idea of passing data between these pages and actionBeans correct?


Solution

  • OK, I had to use a workaround, which I don't like at all. Still, it works. but if you have any suggestions, please, write.

    I passed the parameters from JSP1 to JSP2 in URL using JavaScript redirect. Straight-forward method, but it solved the problem (JSPs didn't redirect when I tried to redirect using Resolution):

        window.location.href ="jsp2.jsp?myparameters"+$.param(myparameters);
    

    In JSP2 I used AJAX to call JSP2 actionBean.

    if (window.location.search.indexOf("myparameters") != -1){
                values = window.location.search.substr(window.location.search.indexOf("myparameters"), window.location.search.length);
                values = decodeURIComponent( values );
    //some parsing here, didn't include it                  
                  $.ajax({
                        url: "JSP2.action?from_redirect=",                     
                        data: {values: values}, 
                        type: "POST",
                        success: function(data) {
                           displayValues(data)
                        }
                    });
    

    And in JSP2.action I made the from_redirect listener return:

       return new StreamingResolution("application/javascript", data);
    

    So, this method works, but I don't like 1 extra redirect. if you have any suggestions, how to solve the problem with Resolutions, please write them. Also I would appreciate any help concerning removing extra redirects in this method.