Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Struts 2 »

Re: how to go back to input page?

Christopher Schultz

2007-01-24

Replies:

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Heidy,

Heidy Guti??rrez Guzm??n wrote:
> In the application, i have the option of change language from any page.

What about using the "referer" header (yes, it is misspelled)?

- -chris

Here is the code for my entire SwitchLocaleAction.java:

import java.util.Locale;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class SwitchLocaleAction
  extends BaseAction
{
  public ActionForward execute(ActionMapping mapping,
                     ActionForm form,
                     HttpServletRequest request,
                     HttpServletResponse response)
    throws Exception
  {
    String language = request.getParameter("lang");
    String country = request.getParameter("country");

    Locale locale;

    if(null == language)
       throw new ServletException("No language specified.");

    if(null == country)
    {
       locale = new Locale(language);
    }
    else
    {
       locale = new Locale(language, country);
    }

    super.setLocale(request, locale);

    String redirect = request.getParameter("next");

    if(null == redirect)
       redirect = request.getHeader("referer");

    if(null != redirect)
    {
       if(0 > redirect.indexOf(";jsessionid="))
          redirect = response.encodeRedirectURL(redirect);

       response.sendRedirect(redirect);
    }
    else
       response.getWriter().write("Cannot determine next page.
Please go back manually.");

    return null;
  }
}

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFFt+gu9CaO5/Lv0PARAsQ3AKCxLXVLRev3ugNkvUPfNShdPgdpswCfS/MM
ckUc1hmZ9CGDK6yY4ZVat4M=
=dKxM
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@(protected)
For additional commands, e-mail: user-help@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.