Link to home
Start Free TrialLog in
Avatar of muthiahmerchant
muthiahmerchant

asked on

struts problem determining the location of css file.

I have a small struts application. I am having difficutlies get to my css file using the following.

<link rel="STYLESHEET" TYPE="text/css" href="/css/styles.css" >

what should i put in the href. My styles.css is located in project/WEB/css

how do i determine the relative path.

Thanks
Avatar of sompol_kiatkamolchai
sompol_kiatkamolchai
Flag of Thailand image

Hi,

It's relative path to you jsp or html file.
If you jsp/html put in project/WEB and your .css put in project/WEB/css,
so href should be href="./css/styles.css"

sompol
but if you define href like "/css/style.css" that mean it is absolute path and you have to put .css file in root folder.
Avatar of muthiahmerchant
muthiahmerchant

ASKER

the problem is I am using struts and the urls to access struts does not represent the actual location of the jsp file

for example to go to the login page I use http://localhost/project/login.do, but login.jsp resides in project/web/jsp/login.jsp

hence i think my relative path should not be with respect to the url. is there any other way.

Thanks for your help
Is this CSS called from login.jsp?

Try to use this as well
<link rel="STYLESHEET" TYPE="text/css" href="css/styles.css" >

David
The css is called from another file which is part of struts tiles
> the problem is I am using struts and the urls to access struts does not represent the actual location of the jsp file


use the base tag to specify the base url for your pages

http://www.w3schools.com/tags/tag_base.asp
or try to use this one.

href="<%=request.getContextPath%>/web/css/style.css"
ASKER CERTIFIED SOLUTION
Avatar of boonleng
boonleng
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks to all your comments.

since I am using struts I will go with the boonleng's solution.

Thanks again