Redirect url to Vaadin window problem

Hi,

I’m replacing an existing Spring MVC app with a Vaadin app. Therefore I need to support “old links” that are jumping into the app from outside. These links are like this: http://localhost:8080/app-name/page.htm?id=111&user=aaa

When I receive such a request, I have to create a new Vaadin window that shows the data that id 111 is related to (/app-name/new_page_111). When I enter the new url manually in the browser I get the desired Vaadin window, but when I try to redirect, I get a new browser window showing the new page but with the old url! In addition, when I click in the main application window on a component, the new window is opened again with the correct url.

I have a Servlet extending ApplicationServlet that handles all normal requests (see below). When I discover an old link I forward the rquest via a RequestDispatcher to the new url that the Vaadin window is using. It seems to me, that the request for the new window is somewhere in the queue and just needs an UI update to be activated…

Can somebody please tell me how to avoid the wrong url in the right window and how to suppress the second openeing of the window? The second problem is probably related to the wrong url and might go away when I have the right url from the beginning.

Code sample:

  protected void service(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException
  {
    String pathInfo = request.getPathInfo();
    if (pathInfo != null && pathInfo.equals("/page.htm"))
    {
      String idStr = request.getParameter("id");
      if (invIdStr != null)
      {
        Long id = Long.parseLong(idStr);
        try
        {
          Application app = getExistingApplication(request, false);
          if (app != null)
          {
            RequestDispatcher rd = request.getRequestDispatcher("/new_page_" + id);
            if (rd != null)
            {
              rd.forward(request, response);
            }
          }
          return;
        }
        catch (MalformedURLException ex)
        {
        }
        catch (SessionExpiredException ex)
        {
        }
      }
    }
    super.service(request, response);
  }

Thanks

Andreas

Hi Andreas,

I think you want to use a Redirect as opposed to a Forward.

A servlet “forward” happens only on the server. It shouldn’t update the URL.

A redirect happens in the browser - essentially, the server says “Hey, Browser! This page you asked for? It isn’t here any more, it’s over here! http://www.newplace.com”; the browser says “Doh, Silly me!” and changes it’s URL to the new location. The effect is exactly as if the user had clicked on the original URL. Both URLs will be in the history.

See
http://goo.gl/bg29O
, or use the power of google for more on the difference.

So, I’d change lines 13-22 to something like :


         Application app = getExistingApplication(request, false);
           if (app != null)
          {
               request.sendRedirect("/new_page_" + id);
          }
          return;

HTH

Cheers,
Charles.

Hi Charles,

you’re right: a Redirect is more appropriate than a Forward in my case.

Thanks for your reply

Andreas