开发者

Spring url not resolving correctly first time jsp page is loaded, works correctly after first hit

开发者 https://www.devze.com 2023-04-02 09:39 出处:网络
Source code: <c:url var=\"images\" value=\"/images/\" /> <link rel=\"icon\" type=\"image/png\" href=\"${images}myImage.png\">

Source code:

<c:url var="images" value="/images/" />
<link rel="icon" type="image/png" href="${images}myImage.png">

In firebug, first hit (the sessionid changes 开发者_运维技巧each time)

 <link href="/images/;jsessionid=05083AEAAE29DE81A5CB390407041282myImage.png" type="image/png" rel="icon">

Second hit (without clearing cache, if I clear cache it goes back to above)

<link href="/images/myImage.png" type="image/png" rel="icon">

So obviously the first time I hit website it looks bad as no resources are being loaded correctly.

Help please ?


The jessionid part is the client session ID, and the first time you hit the page you're likely getting a cookie, so that on the next time you hit the page it doesn't need to be pushed into the URLs. Looking at the JSTL def'n for c:url, you should be giving it the whole URL, not a partial path, so this would be the correct approach:

<c:url var="images" value="/images/myImage.png" />
<link rel="icon" type="image/png" href="${images}">

See also A JSTL primer, Part 2.

0

精彩评论

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