0

Using Eclipse - Dynamic Web Project. I am basically showing page "Home.jsp" via this code in servlet

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
{

    request.getRequestDispatcher("/WEB-INF/Home.jsp").forward(request, response);
}

But styles are not applied this way like they are when directly showing page via url (or just opening html file directly in file system). Is there some way how to apply them in doGet method (or somewhere else) ?

jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
 <title>System</title>
 <link rel="stylesheet" href="styles.css">
</head>
<body>
 <button type="button" class="homebutt">Concerts</button>
 <button type="button" class="loginbutt">Login</button>
 <button type="button" class="registrationbutt">Registration</button>
  <hr>
 <div>
  <select id="artistcombo">
     <option value="">Artist:</option>
  </select>
  
  <select id="countrycombo">
     <option value="">Country:</option>
  </select>
   
  <select id="genrecombo">
     <option value="">Genre:</option>
  </select>
 </div>
  <hr>
</body>
</html>

css:

button
{
 font-family: Helvetica, sans-serif;
}

button.homebutt
{
 font-size: 30px;
 text-align: left;
 background: none;
 border: none;
 color: indigo;
}

button.loginbutt
{
 color: black;
 background: none;
 border: none;
 font-size: 24px;
 float: right;
 text-align: right;
}

button.registrationbutt
{
 color: black;
 background: none;
 border: none;
 font-size: 24px;
 float: right;
 text-align: right;
}

Project tree: Project tree

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Wortig
  • 963
  • 2
  • 11
  • 37
  • Do not post image of your code! Read [here](https://stackoverflow.com/help/how-to-ask) for how to ask a question in stackoverflow. Anyway, please add your jsp code and the tree of your project. – Renato May 08 '20 at 14:34

1 Answers1

0

All files in the WEB-INF directory are not directly accessible to the end user. My suggestion is

  1. move your css file to a directory outside WEB-INF but at the same level e.g. resources
  2. change the import of the css file in the jsp as <link rel="stylesheet" href="${pageContext.request.contextPath}/resources/style.css/>"
Renato
  • 2,077
  • 1
  • 11
  • 22