user3898594
user3898594

Reputation: 153

How to include css files in JSP page struts2?

I'm new to java. And now I'm doing Struts2 project. I added stylesheet in this path

/WEB-INF/common/css/style.css

and added bootstrap in this path

/WEB-INF/common/css/bootstrap/bootstrap.min.css

and included them in JSP file as

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="/WEB-INF/common/css/bootstrap/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="/WEB-INF/common/css/style.css" rel="stylesheet" type="text/css">
<title>Login</title>

But css doesn't work when I run the program. What do I need to do in Struts2 to include CSS files?

Upvotes: 1

Views: 8694

Answers (4)

HASNEN LAXMIDHAR
HASNEN LAXMIDHAR

Reputation: 72

First put all css file and js file put in one JSP page and then that jsp page include in jsp page using tag...

fine i.e.<%@include file="header.jsp"%>

Upvotes: 1

hermansen
hermansen

Reputation: 156

You need to move your css files out of the WEB-INF directory since it is not public. Here is a good explanation of what WEB-INF is and how it should be used: What is WEB-INF used for in a Java EE web application?

Upvotes: 1

Girish
Girish

Reputation: 107

The CSS file path is depending upon where your JSP files are located. Share your project folder structure.

For example:

Application name
   |
   | - WEB_INF
   | - JSP -(If this folder having JSP files)
   | - common/css
   | - JS

Then the path of CSS in JSP file is like

<link href="../common/css/style.css" rel="stylesheet" type="text/css">

Here single .(dot) represent current directory that is JSP Direcrory(Folder)

and double ..(dot) previous/upper directory that is Application/Main project directory, from this directory its points to /common/css/style.css

Upvotes: 1

davidtall
davidtall

Reputation: 13

you can't include CSS files in /WEB-INF path, take it in the web root path ,and use /common/css/style.css to access your page

Upvotes: 0

Related Questions