aspose file tools*
The moose likes Servlets and the fly likes css path Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "css path" Watch "css path" New topic
Author

css path

miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
i've this servlet that generates an html page, but i dont know where to put my css file, so that it is recognized and starts working
in my servlet i have:

my servlet is right inside classes folder and i have my css file there too, but doesnt work
in web.xml i have:

i also tried having my css one folder up, but without result too...
what am i missing?

TiA


java amateur
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
case solved
i put my css inside root folder and in servlet i wrote instead:
out.println("<link href=\"../blog.css\" rel=\"stylesheet\" type=\"text/css\" />");
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60045
    
  65

URL-relative addressing of resources such as images, script files and style sheets are problematic in the servlet environment. It's best to use context-relative addressing.

Bear in mind that what you've done could still be a source of problems. You'd be best off by using syntax that would generate HTML such as:

<link href="/contextPath/blog.css" ...

The contextPath is available from the request instance.
[ November 17, 2006: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
thanks, Bear, for your improvement
now i have:
,
which translates to:
<link href="/css/blog.css" rel="stylesheet" type="text/css" />

BTW, i'd like to grab the oportunity to adress a question that i have in my mind for a while: i've read some (beginers) tutorials on servlets and jsp, and all of them refer that servlets are suitable for code and jsp for html (said in a short and imprecise way)
anyway, all database code i found use servlets - so i end up with the usual mess of code and print statements!
i wonder if there is a way to split things: jsp would be in charge of presentation and servlet would deal with database stuff

What should i read about to get it going that way? (maybe "sending" the recordset to the jsp...)

TiA
[ November 17, 2006: Message edited by: miguel lisboa ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60045
    
  65

Originally posted by miguel lisboa:
i wonder if there is a way to split things: jsp would be in charge of presentation and servlet would deal with database stuff


Yes! That's the best pattern to follow and it's very common. It's known a "Model 2".

This article might be helpful.

maybe "sending" the recordset to the jsp...


You will be sending the data to the JSP, but not as a result set. That's a database concept and should remain sequenstered in model/business code. The model layer should abstract the data into POJOs or DTOs for use by the UI layer.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Whenever a resource location starts with '/' , the container starts from the root of your web application.


Rahul Bhattacharjee
LinkedIn - Blog
Jeroen T Wenting
Ranch Hand

Joined: Apr 21, 2006
Posts: 1847
Wrong. It started from the webserver contextroot.
If there is only one application running on it that's the root of your webapp.
If there are several it can be anywhere.


42
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: css path
 
Similar Threads
about web.xml file.
listeners declaration: before or after servlet ?
Change URL http/unbeatableonline.com/swbeatableonline.com to http/unbeatableonline.com
welcome file list
Wildcard mapping