File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

uri to access stylesheet

 
David Chen
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 254
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)?
 
David Chen
Ranch Hand
Posts: 57
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic