• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

including a css file to a jsp from another folder

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
okay, so what should be the suggested way of including css files in a jsp?
 
Bear Bibeault
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Use an absolute path, including the app context.
 
Bear Bibeault
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
Marshal
Posts: 67279
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
You ridiculous clown, did you think you could get away with it? This is my favorite tiny ad!
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!