If you're just trying to get the context path, you can just use
${pageContext.request.contextPath}. That way you can just write:
<link rel="stylesheet" type="text/css"
href="${pageContext.request.contextPath}/css/myStyles.css" />
If you're using Freemarker, its even easier, just use ${base} like this:
<link rel="stylesheet" type="text/css" href="${base}/css/myStyles.css" />
You can't just specify "css/myStyles.css" as the value of the href tag as
that will be interpreted as a relative path. Actually, you could even do
that, just make sure all your actions are only one level deep (can't use
/user/blah.action etc.)
If you find a better way, do post the solution. I'm curious.
Zarar
maxmil wrote:
>
> Thanks for the respones.
>
> Perhaps i didn't explain myself properly. What i'm really looking for is
> a way to define the context root url as the base url.
>
> My motives for doing this is to allow me to share code across my
> application. An example would be referencing a style sheet in a header
> include. For examples i could use the line
>
> <link rel="stylesheet" type="text/css" href="css/myStyles.css" />
>
> in any jsp, irrespective of the request url that i am calling it from.
>
> Up till now the only solution that i've found is to generate all href
> values using a combination of s:url and s:properties, like so.
>
> <s:url id="myStylesUrl" value="/css/myStyles.css" />
> <link rel="stylesheet" type="text/css" href="<s:property
> name="myStylesUrl" />" />
>
> This generates a context relative url and works fine but is a bit
> cumbersome if i have to do it every time i need to generate a url
> outside struts tags.
>
> max
>
>
> This works fine but h
>
> Musachy Barroso wrote:
>> Or the scriptletless version:
>>
>> <base id="docBase" href='<s:property value="%{#context[@
>> [EMAIL PROTECTED]"/>' >
>>
>> musachy
>>
>> On 6/21/07, Van Riper <[EMAIL PROTECTED]> wrote:
>>>
>>> On 6/21/07, Max Pimm <[EMAIL PROTECTED]> wrote:
>>> > I am used to defining a base element in my pages but can't find the
>>> way
>>> > to define this with struts 2. All suggestions welcome.
>>>
>>> I don't think you need struts 2 support to do this. I'm using webwork
>>> 2.2 currently and starting to monitor this list again in preparation
>>> for migrating our webapp codebase to struts 2. We also use Sitemesh
>>> for response decoration. So, our Sitemesh decorator sets the base
>>> element for our response during the execution of sitemesh response
>>> filter. The way we do it in JSP land is:
>>>
>>> <base id="docBase" href="<%=request.getRequestURL()%>"/>
>>>
>>> No webapp framework support required. We give the base element an "id"
>>> because we have some javascript functions that need to access the base
>>> document URL dynamically. This makes it easy to do the element lookup
>>> by id via Javascript elsewhere.
>>>
>>> Cheers, Van
>>>
>>> Mike Van Riper
>>> [EMAIL PROTECTED]
>>>
>>> Silicon Valley Web Developer JUG
>>> https://sv-web-jug.dev.java.net
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>>
>>>
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
>
--
View this message in context:
http://www.nabble.com/s2%3A-Base-url-in-jsp%27s-tf3958382.html#a11279336
Sent from the Struts - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]