开发者

amp is included in url struts tag

In my web application, I use strust2 url tag to pass parameters like id etc., For example, I use a link to delete an entity and I use param to pass the id of the e开发者_Go百科ntity to be deleted. And I follow this throughout my web app for adding, editing, deleting an entity.

During run time, sometimes, I don't get the params to be stored in my action's bean properties. When I see the link that is generated, I get something like

<a href='/projit1/p/discuss/viewDiscussion.action?d=11&amp;amp;amp;projid=11&amp;amp;disid=4'>

What are these amps for ? why do they sit in between the action calls (made by link via url tag actions ) ? By the time I traverse back and forth in my web app, I get 10s and 20s of amp sitting in the request URL. What is the problem here ? Please help.


In HTML, XHTML and XML certain characters are treated specially. The special characters used the most are less then (<) and ampersand (&). The < is only valid at the beginning of a tag, while the & is used to encode character entities (special characters, characters that can't be typed, etc.). Because & is special and can not appear as part of an attribute value it is encoded as &amp; and while it may look strange if you don't know why, the href value in your question is almost correct. In the same manor < should be encoded as &lt; to ensure correct browser behavior. Not encoding these characters MAY work but is NOT GUARANTEED to work.

The problem with your URL is with multiple amp; what this indicates is the href has been encoded multiple times. The first time & was changed to &amp; at that time another parameter was added with it's & separator. The whole URL was then encoded a second time changeing the first & to &amp;amp; and the second to &amp;. Then for some reason the URL was encoded a third time causing the first to change to &amp;amp;amp; and the second to &amp;amp;. To remove the excess amp;s you need to ensure the URL is only encoded for HTML once not multiple times.

Your resulting tag should look like this:

<a href='/projit1/p/discuss/viewDiscussion.actiond=11&amp;projid=11&amp;disid=4'>


I have found the problem. Hope it helps others.

I will have to set includeParams to none. It will avoid old request parameters


Add below attribute to the url tag

escapeAmp="false"


I know this is a bit old but I ran into the same problem and solved it thanks to luckydev. Here is my code sample:

<s:url id="remoteurlGrid" action="certificationListJSON" includeParams="get">
     <s:param name="population" value="%{getPopulation()}" />
     <s:param name="selectedSalesRepID" value="%{getSelectedSalesRepID()}" />
</s:url>

All I needed to do was add "includeParams="get". The odd thing is that that SHOULD be the default so why it didn't work I don't know.

Here is a reference to the API: http://struts.apache.org/2.1.6/struts2-core/apidocs/org/apache/struts2/components/URL.html

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜