File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes uri to access stylesheet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "uri to access stylesheet" Watch "uri to access stylesheet" New topic

uri to access stylesheet

David Chen
Ranch Hand

Joined: Jan 06, 2002
Posts: 57
Hi, there:

As a newbie to struts, I have problem to access my stylesheet in my jsp file.

| |_____login.jsp
| |_____stylesheet.css
| |_____imgs
| |______logo.gif

so in my login.jsp I used:
href="stylesheet.css" or "./stylesheet.css" which works fine at very beginning however, after validation, it lost stylesheet uri. So, how can I use an absolute uri in my case?

Thanks a lot
David Chen
Ranch Hand

Joined: Jan 06, 2002
Posts: 57
It seems I should use absolute uri for stylesheet like:
then it works on both beginning and after validation. Could someone explain me why? some reasons from struts?

Thanks a lot

Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
So you are saying, when validation fails browser does not apply stylesheet? Is the url correct in the style tag? What is the servlet mapping for your action servlet and what are the relevant url's (of the action)?
SCJP 1.4
David Chen
Ranch Hand

Joined: Jan 06, 2002
Posts: 57
Hi, Kerry:

Thank you for the reply. Yes, it seems the stylesheet can't be located by using relative path after validation.
The files structure was listed in my original post, and in my login.jsp if I use:
<link rel="stylesheet" href="config.css" type="text/css">
it works the first time login.jsp is invoked, however it can't find my stylesheet after validation found some errors. And same problem if I used:
I should use something like:
<link rel="stylesheet" href="/mywebapp/pages/config.css" type="text/css">
then works both at the first time and after validation.

my struts_config.xml looks like:

<action path="/login" type="" name="userLoginForm" input="/pages/login.jsp" validate="true">
<forward name="validUser" path="/pages/MainMenu.jsp" redirect="false" />

Greatly appreciated if any suggestion, comment, idea and helps on it.

Thanks a lot
michelle Wang
Ranch Hand

Joined: Jan 12, 2004
Posts: 65
In this case, if you want to apply css, you may try this:
In the struts-config.xml file, create a simple
<global forward>
<forward name="myStyle" path="/myroot/css/mystype.css"/>
</global forward>

On any JSP page you wish to associate this file with, use

<link rel="stylesheet" type="text/css" href="<html:rewrite forward='myStyle'/>"/>

Happy coding!

michelle Wang <br />SCJP 1.4
I agree. Here's the link:
subject: uri to access stylesheet
It's not a secret anymore!