Struts 2:link + img做双重请求,但为什么呢?

时间:2011-12-15 07:47:40

标签: html jsp hyperlink struts2 request

我有一个大问题。我有一个包含一些值的列表。每次我点击它,它都会切换从ASC到DESC或从DESC到ASC的排序。现在我想显示一个显示排序状态的img(ASC向上箭头,DESC向下箭头)。 如果没有img它工作得很好,但是当我将动态img Tag放入其中时,我向服务器发送一个双重请求,以便使用toggeling cant函数。 我的逻辑是这样的:如果DESC之前比现在使用ASC ....如果Asc之前比现在使用DESC。 我的JSP看起来像这样(getSort()返回排序“status”的实际String):

    `<s:if test="getSort()=='DESC'">
    <s:set name="sortierBild1" value="'/styles/img/buttons/pfeil-unten.GIF'"/>
    </s:if>
    <s:if test="getSort()=='ASC'">
    <s:set name="sortierBild1" value="'/styles/img/buttons/pfeil-unten.GIF'"/>
    </s:if>`




   `<th id="Berichtsjahr" class="sortable">
    <s:url id="SortBerichtsjahrURL" action="planIdentUebersicht_sort">
    <s:param name="sortBy" value="1" />
    </s:url>
    <a href="${SortBerichtsjahrURL}" class="action">BJahr
    <img src="<s:url value='%{sortierBild1}'/>" class="icon"></a>
    </th>`

通过这个安排,它发送双重请求,我的逻辑无法切换! 没有img-part(<img src="<s:url value='%{sortierBild1}'/>" class="icon">)的相同代码功能很棒!

请帮帮我! 问候。

1 个答案:

答案 0 :(得分:0)

您的二传手<s:set name="sortierBild1" value="'/styles/img/buttons/pfeil-unten.GIF'"/>将值sortierBild1设置为'/styles/img/buttons/pfeil-unten.GIF'。当值放在那里时,<img src="<s:url value='%{sortierBild1}'/>"会看起来像这样:

<img src="<s:url value=''/styles/img/buttons/pfeil-unten.GIF''/>"

我猜2x单引号会破坏标记或生成这样的标记:

<img src="http://www.domain.tld/app/'/styles/img/buttons/pfeil-unten.GIF'" />