• 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

including a css file to a jsp from another folder

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all.. how can i include the link of the css file to my jsp? here's the directory hierarchy and the code i tried (but didn't work).. please help..


my jsp file is in the web folder


<head>
<title>refreshed</title>
<meta http-equiv="Content-Type" content="text/HTML; charset=UTF-8" />
<link rel="stylesheet" type="text/css" href="../src/java/Style/style.css" />
</head>
 
Rancher
Posts: 377
Android Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

Shouldn't you have your styles (and images) in your web folder. In a typical java web-app you would have them in the same folder that contains your WEB-INF folder and then reference them absolutely rather than relatively as you have done in your example.

Sean
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As mentioned, all CSS and JavaScript files should be in the web content folder*. Since they're not Java source, they shouldn't be in anything called "java", because nobody would ever think to look there for non-Java resources.

* At least after deployment. Before deployment they can be anywhere you want.
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And once you've moved the file to an appropriate location, be sure that you fix the URL in your page. It should be server-relative, starting with the context path.
 
Jhodee Rigodon
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
alright..thanks for the response... it's all working now..after i transferred the images and stylesheets to the web folder
and did something like <link rel="stylesheet" type="text/css" href="Style/style.css" />

i still have a question though... well, if given the chance to still keep the original locations of the files (basing on the image), what's the reason why my initial code (<link rel="stylesheet" type="text/css" href="../src/java/Style/style.css" />) didn't work? just wanna clear things out..
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly, you are still using page-relative addressing, and while that may be working for you, it's fragile and not a good practice.

Secondly, it didn't work because the file wasn't part of the web app and couldn't be served.
 
Jhodee Rigodon
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
okay, so what should be the suggested way of including css files in a jsp?
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See my first reply. It's also covered in the JSP FAQ.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use an absolute path, including the app context.
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:Use an absolute path, including the app context.


I prefer the term "server-relative" because most people think of "absolute" as including the http:// and domain parts.
 
Jhodee Rigodon
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm kinda new in this field, so could you show me some example of that "server-relative" way of including the css??
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's all in the JSP FAQ.
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:I prefer the term "server-relative" because most people think of "absolute" as including the http:// and domain parts.


Good point.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic