This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Not JSP. Anyone know how to just use .html files  RSS feed

 
ranger
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So basically I have a Java Web Application built on top of Servlets and JSP spec. However, I am not using .jsp files. I have just straight .html pages as all the dynamic content will come from ajax calls and json.

I have been able to display my index.html page, but none of the css styling is happening even though I see the links to the stylesheets in the view source. The pathing should work.

Anyone know if they have to be .jsp pages to get those links to the stylesheets to work

WEB-INF
--index.html
--css/style.css

and on my html page

<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/3.4.1/build/cssreset/cssreset-min.css">
<link href="css/style.css" rel="stylesheet">


The rest is irrelevant.

Thanks

Mark
 
Saloon Keeper
Posts: 5043
134
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you used a tool like LiveHTTPHeaders or Firebug to ascertain that the CSS files are being accessed OK (meaning, the requests result in 200 or 304 responses) ?
 
Marshal
Posts: 67164
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chrome and Safari have excellent built-in network tools to see what files are being loaded, and even how long they take, and in what order.

I always advise against using page-relative addressing in web apps. It's fragile and easily broken. Better to use server-relative addressing that starts with the context path. Because they are static HTML files, that means you'd have to hard-code the context path. Ick.

Me, I'd like convert them to JSPs just so I could grab the context path dynamically.
 
Mark Spritzler
ranger
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Chrome and Safari have excellent built-in network tools to see what files are being loaded, and even how long they take, and in what order.

I always advise against using page-relative addressing in web apps. It's fragile and easily broken. Better to use server-relative addressing that starts with the context path. Because they are static HTML files, that means you'd have to hard-code the context path. Ick.

Me, I'd like convert them to JSPs just so I could grab the context path dynamically.



Thanks. I think going to jsp might be what I do. I mean I can use jstl and do some looping and stuff, which I wouldn't get through straight html.

Do you have an example of the jsp line for using server-relative addressing, so if my css files are in my war files WEB-INF/css directory?

THanks

Mark
 
Bear Bibeault
Marshal
Posts: 67164
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
CSS files can't be under WEB-INF. The container cannot serve anything out of WEB-INF or its sub-folders. Resources such as style sheets, images and script files must not be under WEB-INF.

If the css files were under, say resources/styles, a typical URL would be:
 
Sheriff
Posts: 21465
97
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Bear Bibeault wrote:CSS files can't be under WEB-INF. The container cannot serve anything out of WEB-INF or its sub-folders.


It can, but it would need a servlet and URL mapping for this content. For the resources you mention it's not worth it though. The only reason to put them in WEB-INF is to hide them from the "outside world", and by creating a servlet and URL mapping you would be unhiding them. Then what's the point of hiding them in the first place?

So I agree, don't put these resources in WEB-INF.
 
Mark Spritzler
ranger
Posts: 17314
11
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, I don't know why I always thought that all those files were in the WEB-INF directory in all the projects I have done at companies, but looking back at those projects, I see that they are indeed outside of the WEB-INF directory.

Now for server related paths, is jsp the only way to get the context path easily, or can it be done in straight html pages?

Thanks

Mark
 
Bear Bibeault
Marshal
Posts: 67164
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no way to get the context path programmatically without JSP or some other server-side assist.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!