• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

uri to access stylesheet

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic