Thursday, March 31, 2011

use struts tags inside attributes in jspx files

I have some old jsp code that uses the struts tags inside attributes, like this:

<link href="<s:url value='/styles/layout.css'/>" 
  rel="stylesheet" type="text/css" media="all"/>

I can't get this to work in jspx files though. Is there a good alternative to sort of get the same functionality without too much clutter?

From stackoverflow
  • Try this

        <c:set var="myUrl"><s:url value='/styles/layout.css'/></c:set>
        <link href="${myUrl}"/>
    

    You may also want to try this form, but I cannot really remember if it works:

        <s:url value='/styles/layout.css' var="anUrl"/>
        <link href="${anUrl}"/>
    
    wds : Is it then functionally impossible to use the s:url tag inside of the href-tag? There's almost no instances in this code where s:url is called more than once on a page, so that's going to create a host of one-time vars.

0 comments:

Post a Comment