Hi all, I had the same problem.. I think there's nothing in Struts to achieve a redirect + parameters..
If you do this : > myForward = mapping.findForward("toSomeAction"); > myForward.setRedirect(true); > myForward.setQueryString(someJavaUtilMap); > return myForward; As the mapping.findForward() return you the *common* instance of ActionForward, you'll end up with a messy ActionForward, as each time you'll execute this code, the ActionForward keeps you're QueryString from one call to another. I finally code a quick and dirty method in my 'Mother of all' Action to allow forward redirects : One to 'clone' an ActionForward, based on the mapping : public ActionForward cloneActionForward(ActionMapping mapping, String name) { ActionForward af = mapping.findForward(name); if (af == null ) { return null; } StringBuffer url = new StringBuffer(af.getPath()); actionCache.addParams(url); af.setPath(url.toString()); logger.debug("cloneActionForward : "+url.toString()); ActionForward copyAF = new ActionForward(); copyAF.setName(af.getName()); copyAF.setPath(af.getPath()); copyAF.setRedirect(af.getRedirect()); return copyAF; } And an other one to add a parameter, and 'URL-Encode' it : public ActionForward addParameter(ActionForward fwd, String key, Object value) { StringBuffer path = new StringBuffer( fwd.getPath() ); UrlUtil.addParam(path,key,value); fwd.setPath( path.toString() ); return fwd; } So now, I redirect this way in my actions : public ActionForward insert(ActionMapping mapping, SicolActionForm form, HttpServletRequest req, HttpServletResponse resp) throws ServletException, TorqueException, BusinessException { // Code here that does an insert in database // as we dont't want a 'Refresh' to re-fire this action, let's redirect to the view : ActionForward fwd = cloneActionForward(mapping, "displayView"); return addParameter(fwd, "key", obj.getPrimaryKey()); } Hope this helps. Alex. PS : I think this kind of fonctionality should be Struts-native, no ? Or maybe we're the only one doing redirects here ? > -----Message d'origine----- > De : Arik Levin ( Tikal ) [mailto:[EMAIL PROTECTED]] > Envoyé : mardi 11 juin 2002 08:52 > À : 'Struts Users Mailing List' > Objet : RE: Adding query string to redirect w/in an action > > > If you are redirecting from one action to another it's true, > I had this problem, you can always use forward ;-) > > -----Original Message----- > From: Roy Truelove [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, June 11, 2002 4:01 AM > To: Struts Users Mailing List > Subject: Adding query string to redirect w/in an action > > Hello all, > > Question about redirects.. I want to redirect from one action > to another, but I want to append a query string to the URL. > I know how to do this the "dirty" way, by creating a > context-relative ActionForward and slapping the queryString > onto the end. What I'm looking for (in theory) is the > equivalent to this : > > myForward = mapping.findForward("toSomeAction"); > myForward.setRedirect(true); > myForward.setQueryString(someJavaUtilMap); > return myForward; > > Is there a clean way to add a query string to a redirect when > the redirect goes to an action? > > Thanks, > Roy > > > -- > To unsubscribe, e-mail: > <mailto:struts-user-> [EMAIL PROTECTED]> > For > additional commands, > e-mail: <mailto:[EMAIL PROTECTED]> > -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>