Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not sure what is meant with <code>prefix</code>, I assume you are referring to the servlet's name. Suppose you have this <em>forward</em> in your <code>struts-config.xml</code> as part of an <code>action</code> mapping:</p> <pre><code>&lt;forward name="test" path="/switch" /&gt; </code></pre> <p>If you want to get the <em>forwards'</em> names available to your action, you can get them with <code>mapping.findForwards()</code>.</p> <p>If you already have a <code>forward</code>, for example:</p> <pre><code>ActionForward forward = mapping.findForward("test"); </code></pre> <p>you can get the name of the forward with:</p> <pre><code>String fwdName = forward.getName(); // returns "test" </code></pre> <p>and the servlet name or path with:</p> <pre><code>String servletPath = forward.getPath(); // returns "/switch.do" </code></pre> <p>you can also get it from the <code>request</code> object:</p> <pre><code>String servletPath = request.getServletPath(); </code></pre> <p>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 <code>ActionForward</code> based on one of the forwards defined in your <code>struts-config.xml</code>, like for example:</p> <pre><code>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" </code></pre> <p>This would tell Struts to issue a redirect to an URL like <code>/switch.do?id=3</code></p> <p>Knowing how to create a new <code>ActionForward</code>, 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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload