File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problems with Servlets + CSS + forward

 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic