aspose file tools*
The moose likes JSP and the fly likes Not JSP. Anyone know how to just use .html files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Not JSP. Anyone know how to just use .html files" Watch "Not JSP. Anyone know how to just use .html files" New topic
Author

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

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Jan 10, 2002
Posts: 61417
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

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

Joined: Jan 10, 2002
Posts: 61417
    
  67

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

Joined: Oct 27, 2005
Posts: 19719
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17257
    
    6

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

Joined: Jan 10, 2002
Posts: 61417
    
  67

There is no way to get the context path programmatically without JSP or some other server-side assist.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Not JSP. Anyone know how to just use .html files