There's any way to use a prefix as a paramter or in the path of a forward like:
????
There's any way to use a prefix as a paramter or in the path of a forward like:
????
I'm not sure what is meant with prefix
, I assume you are referring to the servlet's name. Suppose you have this forward in your struts-config.xml
as part of an action
mapping:
<forward name="test" path="/switch" />
If you want to get the forwards' names available to your action, you can get them with mapping.findForwards()
.
If you already have a forward
, for example:
ActionForward forward = mapping.findForward("test");
you can get the name of the forward with:
String fwdName = forward.getName(); // returns "test"
and the servlet name or path with:
String servletPath = forward.getPath(); // returns "/switch.do"
you can also get it from the request
object:
String servletPath = request.getServletPath();
OK, now, if you want to modify the forward before returning control to Struts, so that you can append extra parameters, you'll need to create a new ActionForward
based on one of the forwards defined in your struts-config.xml
, like for example:
ActionForward forward = mapping.findForward("test");
StringBuilder path = new StringBuilder(forward.getPath());
path.append("?id=");
path.append(someobject.getId());
return new ActionForward(path.toString(), true); // `true` means "do a redirect"
This would tell Struts to issue a redirect to an URL like /switch.do?id=3
Knowing how to create a new ActionForward
, and how to get the names of the forwards and the servlet names they point to, you shouldn't have a problem constructing the forward that you need.