4
<%String path = application.getRealPath("/");%>
<%@page import="index.css" %>

I am using String path as above to get the real path of my directory. I want to import index.css from the css folder.

Is it possible in JSP to do something like <%@page import = path+"css/index.css"%> or is there an easier way to do this?

ILikeTurtles
  • 1,012
  • 4
  • 16
  • 47
  • Are you trying to import a css file on the server-side? – Matt Houser May 31 '13 at 20:58
  • I am coming from a php background so I am used to using include_once and being done with it. Is there nothing similar in JSP? @MattHouser – ILikeTurtles May 31 '13 at 21:00
  • @Aaron: That's not how CSS works. CSS runs on the **client**. – SLaks May 31 '13 at 21:02
  • possible duplicate of [Adding external resources (CSS/JavaScript/images etc) in JSP](http://stackoverflow.com/questions/14548998/adding-external-resources-css-javascript-images-etc-in-jsp) – informatik01 Mar 08 '14 at 18:49

3 Answers3

7

I think you want to include index.css file to jsp. try this

<jsp:include page="index.css"/>

or

<%@include file="/WEB-INF/include/header.jsp"%>

but i recommend to use tag in html

Hai Nguyen
  • 110
  • 8
4

Neither PHP nor JSP have anything to do with CSS.

You can link the resulting HTML to a stylesheet the same way you would in any other HTML, using the <link> tag.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
0

execute css codes from within the jsp page using the it works for me

<style>
        .container {
          alignment-adjust: central; 
        }
</style>
HK boy
  • 1,398
  • 11
  • 17
  • 25