开发者

Forwarding in STRUTS

开发者 https://www.devze.com 2022-12-09 19:05 出处:网络
I am forwarding to an action by givingas <forwardname=\"sample\" path=\"/sample.do?button=default\" />

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 &amp; so that the forward definition looks like this:

<forward  name="sample" path="/sample.do?button=default&amp;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 '&amp;' 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 &amp; or &lt;, as appropriate.

So, the forward statement will be as

<forward  name="sample" path="/sample.do?button=default&amp;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.

0

精彩评论

暂无评论...
验证码 换一张
取 消