• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
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
 
Tim Moores
Bartender
Posts: 2756
38
  • 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) ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64724
86
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
Sheriff
Posts: 17278
6
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
Author and ninkuma
Marshal
Pie
Posts: 64724
86
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:
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java 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
Sheriff
Posts: 17278
6
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
Author and ninkuma
Marshal
Pie
Posts: 64724
86
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic