• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems with Servlets + CSS + forward

 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi fellows..
I have a bunch of jsp pages with a cascading style sheet. If I do forward from a servlet to the JSP the CSS doesn't work, but if I do a response.sendRedirect the jsp 'recognizes' the CSS.
As far as i know, forward is faster because it does not create a new request, so I was using it for this reason. In some cases I'm using redirect because it displays in the status bar in which page the user is currently located.
Has anyone experienced this problem? I'm using Forte for java 4.0 CE bundle with Tomcat.
thanks
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember that with a forward, the browser still thinks it is talking to the servlet URL so that is the base it uses to try to locate additional resources such as images or CSS files. The solution is to either use an absolute URL for your CSS reference or (my favorite) include a BASE tag in the HEAD area of your HTML page to provide the browser with the correct URL.
Bill
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you William


The solution is to include a BASE tag in the HEAD area of your HTML page to provide the browser with the correct URL.


sorry 4 asking this dumb question, but what is the URL i should use?
my web application is in my c drive under:

i tried <base href="http://localhost:8081/"> and <base href="\\"> with no luck
thanks
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The URL has to point to a directory that the web server can serve pages from. If I understand your layout right, try
href="/myCSS"
Generally I think the best way to figure this sort of thing out is to make a plain HTML page prototype. Once you get that working you can convert to a servlet or JSP.
Bill
 
reply
    Bookmark Topic Watch Topic
  • New Topic