Forwarding in STRUTS
I am forwarding to an action by giving as
<forward name="sample" path="/sample.do?button=default" />
i want to add one more attribute in path and i used:
<开发者_如何学C;forward name="sample" path="/sample.do?button=default&value=text" />
...and I am getting org.xml.sax.SAXParseException
Any solution for it?
As Omnipresent and Shashi already said, you must encode the ampersand as &
so that the forward
definition looks like this:
<forward name="sample" path="/sample.do?button=default&value=text" />
However, the URLs defined in your struts-config.xml
are frozen, and if you need to dynamically change a value or add another parameter, you can do it by creating a new ActionForward
based on the forward that you get from mapping.findForward()
.
ActionForward forward = mapping.findForward("sample");
StringBuilder path = new StringBuilder(forward.getPath());
path.append("?id=");
path.append(someobject.getId());
path.append("&value=");
path.append(getValue());
return new ActionForward(path.toString());
<forward name="sample" path="/sample.do?button=default&value=text" />
You can pass multiple parameter in forward. But you have to use '&' instead of '&'.
To be strictly accurate, the parser handler should scan the buffer for ampersand characters (&);and left-angle bracket characters (<)
and replace them with the strings & or <, as appropriate.
So, the forward statement will be as
<forward name="sample" path="/sample.do?button=default&amp;value=text" />
you can not use '&' in struts-config.xml
value=text should be passed from your action...not the way you are trying to pass it (in url).
Your forward tag must be associated with an action. that action should have a getter called value which returns 'text'.
what way sample.do will have access to that varable.
精彩评论