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
LVL 1
muthiahmerchantAsked:
Who is Participating?
 
boonlengCommented:
You can try using <html:rewrite> to render the url path.
<link rel="STYLESHEET" TYPE="text/css" href="<html:rewrite page="/css/styles.css"/>" >
0
 
sompol_kiatkamolchaiCommented:
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
0
 
sompol_kiatkamolchaiCommented:
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.
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
muthiahmerchantAuthor Commented:
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
0
 
suprapto45Commented:
Is this CSS called from login.jsp?

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

David
0
 
muthiahmerchantAuthor Commented:
The css is called from another file which is part of struts tiles
0
 
objectsCommented:
> 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
0
 
sompol_kiatkamolchaiCommented:
or try to use this one.

href="<%=request.getContextPath%>/web/css/style.css"
0
 
muthiahmerchantAuthor Commented:
thanks to all your comments.

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

Thanks again
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.