1

I have following variable to be used as a public variable in the application. As you can see it has the main domain of the website as its value. The issue is, once the application is loaded it does not have any value, I need to refresh the page for it to have its correct value.

<c:set var="url" scope="application"
    value="http://www.example.com" />

I am using Tiles3 and this line is in baseLayout.jsp file.

Code

<link rel="stylesheet"
    href="${url}/resources/mystyle.css">

At first the addresses in the source of the page that are supposed to have the URL value are as following

<link rel="stylesheet"
    href="/resources/mystyle.css">

After refreshing the page the address will become as following

<link rel="stylesheet"
    href="http://www.example.com/resources/mystyle.css">
Daniel Newtown
  • 2,873
  • 8
  • 30
  • 64

1 Answers1

0

in your baseLayout.jsp, use

<link rel="stylesheet" href="resources/style.css" /> 

Dont write ${url}

balboa_21
  • 375
  • 1
  • 7
  • 21
  • great thanks, the only issue is the trick does not work for scripts. Something like if I change the address to resources/js/jquery-ui.min.js it just adds the domain not the project name. – Daniel Newtown May 31 '15 at 02:45
  • are you trying to set `` in baseLayout.jsp ? ... – balboa_21 Jun 01 '15 at 12:35
  • Can you please tell the exact requirement ?...because I still dont understand, since baseLayout.jsp is the very first page to set any value..in later pages if you wanted to use {url} then I would have used `` instead of JSTL but in your case here in baseLayout.jsp (in script tag) you can directly write it.. – balboa_21 Jun 02 '15 at 09:23
  • this line is in baseLayout.jsp but as I explained in the question once the application is loaded, it does not work unless the user refreshs the page. without refreshing – Daniel Newtown Jun 03 '15 at 06:32
  • that is happening because for the very first time when you are coming, you are declaring {url} later but trying to access it before...and once you refresh it..the variable gets initialised and then it works fine – balboa_21 Jun 03 '15 at 09:57
  • Yes, I got that but not sure how to solve the problem. How should I declare URL to avoid this issue. – Daniel Newtown Jun 04 '15 at 00:21
  • I am sorry buddy, I guess by declaring url as a model object in your controller side might help or use JSP Implicit Object..I cant think of other solution... – balboa_21 Jun 04 '15 at 07:25