Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can i connect my css to my JSP files stored in the WEB-INF folder? Websphere/JSP

Tags:

html

css

jsp

I am using ibm websphere and creating a Dynamic web project. All of my JSP files are in my WEB-INF folder and i use servlet mapping in my web.xml file to make them accessible. This has worked fine so far. however i have problem with my CSS. as always, my CSS file is located in WebContent in a folder named css. heres my link for my jsp

<link rel="stylesheet" href = "css/styles.css">

I'm having no luck getting my css to show...
what am i missing?

like image 706
Jimmy Servlet Avatar asked Apr 27 '12 17:04

Jimmy Servlet


1 Answers

The relative URLs in the generated HTML output are by the browser interpreted relative to the request URL (as you see in browser's address bar), not to their physical location in the server's disk file system. It's namely the webbrowser who has got to download them by a HTTP request, it's not the webserver who has got to include them from disk somehow.

One of the ways is to use a domain-relative path for those resources, i.e. start with /. You can use ${pageContext.request.contextPath} to dynamically inline the current webapp's context path.

<link rel="stylesheet" href="${pageContext.request.contextPath}/css/styles.css">

This will end up in the generated HTML output as follows:

<link rel="stylesheet" href="/yourContextPath/css/styles.css">

This way the browser will be able to download them properly.

See also:

  • Browser can't access/find relative resources like CSS, images and links when calling a Servlet which forwards to a JSP
like image 85
BalusC Avatar answered Sep 28 '22 20:09

BalusC