Incorporating CSS into an HTML document with Jersey/Grizzly

This is the structure of my project:

src/main/java
-- main.java
src/main/resources
-- webapp
-- -- css
-- -- js
-- -- images
-- -- pages
-- -- -- home.html

Currently, my Maven project utilizes Jersey and Grizzly. I am able to call my REST services and load static HTML pages using clstatichttphandler. The issue arises when the "home.html" file is loaded - the CSS and images do not display. I have attempted to set the path to the CSS relative to the "home.html" file, but it does not seem to be working.

I suspect that my CSS/images are not visible.

EDIT

Below is the file that initiates the Grizzly server - Main.java

    public static HttpServer startServer() {
    // create a resource config that scans for JAX-RS resources and providers
    // in com.application.easyshow package
    final ResourceConfig rc = new ResourceConfig().packages("com.application.app", "com.businessLogic");
    // create and start a new instance of grizzly http server
    // exposing the Jersey application at BASE_URI
    HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(BASE_URI), rc);

    server.getServerConfiguration().addHttpHandler(
            new org.glassfish.grizzly.http.server.CLStaticHttpHandler(Main.class.getClassLoader(), "/webapp/pages/"), "/app");

    return server;
}

And here is the <head> section where I attempt to load my CSS and JS in home.html

<head>
<meta charset="UTF-8">
<title>Soundbyte Template</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="../css/style.css">
<link rel="stylesheet" href="../css/responsive.css">
<link rel="stylesheet" href="../Player/css/progression-player.css" />
<link href="../Player/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link href='//fonts.googleapis.com/css?family=Poppins:400,600,700%7cRoboto:400,300,700,900' rel='stylesheet' type='text/css'>    
<script src="../js/libs/jquery-1.11.3.js"></script> 
<script src="../js/libs/jquery-migrate.min.js"></script>
<script src="../js/libs/modernizr-2.6.2.min.js"></script>
</head>

Overview of my project's appearance

https://i.sstatic.net/BF3Vv.png

Answer №1

One potential issue could be with the file paths for the css files not being correct. If you specify the path as css/images without a starting point, it will begin from the root directory of the HTML. You can either place your css folder there or start from something like project_name/main/resources/css/images.

I hope this resolves any confusion. :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Challenges with TinyMCE and Drag Interaction

Here's the issue I'm facing with my page. The problem arises when using draggabilly to move the line. Dragging it to the left works fine, but dragging it to the right doesn't function properly in the area where the tinymce compiler is locat ...

Using BZip2/GZip to compress numbers larger than 256 (1 byte) into a more compact form

My main objective is to efficiently store a large number of individual files and read them using Java 1.6. These files contain an average of 125,000 numbers each, ranging from a few hundred to over 7,000,000 in some cases. The numbers typically fall within ...

Using JavaScript to alter CSS styles with dashes

Currently, I'm delving into the world of manipulating CSS using JavaScript: img.style.borderRadius = "100%"; img.style.border = "9px solid #ffffff"; img.style.boxShadow = "0 0 5px #00000070"; img.style.margin = "20px"; I'm wondering how to chan ...

How can you line up various form elements, like pickers, in a row using Material UI?

As someone new to material ui, I haven't come across a solution for my specific issue yet. While there are similar questions, none seem to address the problem of aligning different form field types. My observation is that the material ui date picker ...

Differences between using CSS properties and AngularJS filters:CSS properties

When working on an angularjs application, one task may be to convert a string to uppercase. There are 2 options available to achieve this, both yielding the same result. However, it is important to consider the scenarios in which one option may be preferre ...

Issue with the button border not functioning correctly upon hover

I'm currently practicing my HTML and CSS skills, with a focus on creating buttons. I have encountered an issue where I want a colored border to appear around the button when hovered over. Unfortunately, I seem to be stuck and unable to achieve the des ...

Adding code containing various Google Maps elements in a fresh browser window using JavaScript

I've encountered an issue while trying to create a new page with a Google map and title based on the button clicked. Interestingly, when I copy/paste the HTML in the "newhtml" variable into an actual HTML file, it works perfectly fine. However, it doe ...

Triggering div visibility based on jQuery select change event

I am currently working on a form feature that involves showing a div when a specific option in a select element is chosen, and hiding the div when the option is not selected. Here is the current structure of my markup: Here is the current HTML markup I ha ...

Is there a way to display a secondary header once the page is scrolled down 60 pixels?

.nav-header2{ background: purple; display: flex; justify-content: center; align-items: center; } .header2-container{ width: 68vw; height: 60px; padding: 0 2vh; border: 1px solid red; ...

Utilizing a JavaScript function to toggle the Bootstrap dropdown without the need for manual clicking

I've configured a Bootstrap dropdown in my site's mini cart that includes a lightbox effect to grey out the background content when the dropdown is activated. Here's the code snippet: $(".dropdown").on('show.bs.dropdown hide.bs.dropdow ...

Is it possible to access forms and input fields in an AngularJS script without having to pass them from the HTML code?

Seeking a solution for input field validation, I have written code where input field states are passed from HTML to a script through a function. However, my goal is to directly retrieve the values in the script without passing them from the HTML when calli ...

What is the best way to swap out an icon based on the chosen option?

Here is my code: $('#mySelect').on('change', function() { var value = $(this).val(); $(".title").html(value); }) <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link href=" ...

develop a Java 2D array

Currently, I have a Java code set up to calculate the average of an array and it's working flawlessly. However, I am looking to make modifications so that it can handle a 2D array (Two-dimensional). import java.util.*; public class Test3{ public st ...

issues with conditional statement

I'm encountering an issue with the if statement not functioning as expected, and I can't seem to figure out why. The if condition always gets displayed regardless of the input. To troubleshoot, I initially used a temporary code snippet for the co ...

What can I do to prevent Masonry from floating all of my grid items to the left?

Is there a way to center justify the masonry grid items? I have noticed that my Masonry layout is aligning all the grid items to the left or justifying them to the left side: <div class="wrap"> <div class="parent grid"> <div class=" ...

Activate JavaScript functions by pressing the enter key, allowing for various searches, AJAX requests, and DataTable displays to occur seamlessly without the need to refresh

I recently developed a web page that integrates an AWS API interface to interact with an RDS Aurora MySQL Serverless database. Users can input a SQL statement and click the Query button, which triggers an AJAX request, returns JSON data, and converts the d ...

Trying to connect a webpage to my CSS file

Lately, I've been diving into building a new website. It's still in its early stages and unfortunately, I'm struggling to get the style.css file to cooperate. Despite my best efforts scouring the internet for fixes, I haven't had much l ...

The spacing between elements in Flexbox is too excessive, creating an overly wide gap

How can I maintain a fixed 40 pixel gap between columns in flexbox without it increasing as the screen width widens? (I apologize for the brevity of this description, but there are no additional details to provide at this time) .browser-box { max-wid ...

Changes in an image element's transition can result in either resizing or shifting positions

When I apply an opacity transition to an img element as shown here, I notice that the size of the image changes or it appears to move at the start and end of the transition. Below is a simple CSS code for styling: img{ height:165px; width:165px; ...

Saving customer responses in an array that does not begin at index 0

In the given code snippet, there seems to be a problem in OPTION 2 where if the user specified Store = 1, the item details get overwritten in item[0] instead of being stored in item[7]. The item is located in the constructor method of another class. I am l ...