| Author |
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. mywebapp |_______pages | |_____login.jsp | |_____stylesheet.css | |_____imgs | |______logo.gif |_______WEB-INF 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
|
 |
David Chen
Ranch Hand
Joined: Jan 06, 2002
Posts: 57
|
|
It seems I should use absolute uri for stylesheet like: /mywebapp/pages/stylesheet.css then it works on both beginning and after validation. Could someone explain me why? some reasons from struts? Thanks a lot David
|
 |
Kerry Wilson
Ranch Hand
Joined: Oct 29, 2003
Posts: 251
|
|
|
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)?
|
http://www.goodercode.com
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: href="./config.css" 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="com.xxx.actions.UserLoginAction" name="userLoginForm" input="/pages/login.jsp" validate="true"> <forward name="validUser" path="/pages/MainMenu.jsp" redirect="false" /> </action> Greatly appreciated if any suggestion, comment, idea and helps on it. Thanks a lot David
|
 |
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 <html:rewrite>: <link rel="stylesheet" type="text/css" href="<html:rewrite forward='myStyle'/>"/> Happy coding!
|
michelle Wang <br />SCJP 1.4
|
 |
 |
|
|
subject: uri to access stylesheet
|
|
|