This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

css path

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64631
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever a resource location starts with '/' , the container starts from the root of your web application.
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic