When attempting to load a CSS file, Java automatically redirects to the login page

EDIT**

After successfully loading CSS, I encountered an issue where the page kept redirecting back to login.jsp instead of displaying the CSS. Any insights on what might be causing this?https://i.sstatic.net/Ij7Oh.png


I attempted to incorporate a custom CSS file into the header of my login.jsp page. However, upon running it, the CSS failed to load and an error message stating "too many redirects" was displayed:

too many redirects

I am unsure of how to resolve this issue.

I have made efforts to figure out how to allow CSS/JS/img files, but I lack familiarity with the web.xml file and the recommended approach for validating those entries.

The error message states:

GET http://localhost:8080/AppV2/resource/css/login net::ERR_TOO_MANY_REDIRECTS

login.jsp page:

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<jsp:include page="header.jsp" />
<link rel="stylesheet" href="resource/css/login.css">
<body>
    <%
        String login_msg = (String) request.getAttribute("error");
        if (login_msg != null)
            out.println("<font color=red size=4px>" + login_msg + "</font>");
    %>  
<div class = "container">
    <div class="wrapper">
        <form action="" method="post" name="Login_Form" class="form-signin">       
            <h3 class="form-signin-heading">Welcome Back! Please Sign In</h3>
              <hr class="colorgraph"><br>

              <input type="text" class="form-control" name="Username" placeholder="Username" required="" autofocus="" />
              <input type="password" class="form-control" name="Password" placeholder="Password" required=""/>            

              <button class="btn btn-lg btn-primary btn-block"  name="Submit" value="Login" type="Submit">Login</button>            
        </form>         
    </div>
</div>  
</body>
</html>

Login.java Servlet:

public class LoginServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public LoginServlet() {
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // Set standard HTTP/1.1 no-cache headers.
        response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate");
        // Set standard HTTP/1.0 no-cache header.
        response.setHeader("Pragma", "no-cache");
        if ((request.getParameter("password") == "") && (request.getParameter("password") == "")) {
            request.setAttribute("error", "Invalid Username or Password");
            RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/WEB-INF/views/login.jsp");
            dispatcher.forward(request, response);
        } else if ((request.getParameter("password") == null) && (request.getParameter("password") == null)) {
            RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/WEB-INF/views/login.jsp");
            dispatcher.forward(request, response);
        } else {
            String psw = request.getParameter("password");
            String usr = request.getParameter("username");
            List res = userLoginUtils.logIn(usr, psw);
            Boolean debugFlag = true;
            if (res.get(0).equals("true") || debugFlag == true) {
                this.writeToSession(res.get(1), request);
            } else {
                request.setAttribute("error", "Invalid Username or Password");
                RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher("/WEB-INF/views/login.jsp");
                dispatcher.forward(request, response);

            }
            response.sendRedirect("index");
        }
    }

Thanks

Answer №1

To start, make sure your tag is placed inside your tag (assuming your tag is located within header.jsp).

When it comes to specifying the path of your file: The way you imported it won't work. Instead, try the following approach using EL expressions:

<link type="text/css" rel="stylesheet" href="${pageContext.request.contextPath}/resource/css/login.css" />

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

The height of divs spontaneously changes after resizing without any instructions

I am developing a jQuery function to vertically center an element. The function is triggered on load and here is the code: JQuery var $window_height; function Centerize(content) { content.css('margin-top', (($window_height - content.height( ...

What could be the reason behind the significant void in the grid I designed?

I'm currently learning how to utilize the grid container and have successfully created a grid with 2 images on top, 2 on the bottom, and one that stretches vertically on the left side. While I have arranged the grid as desired, I am facing an issue wi ...

Placing the date of each blog post at the end of the excerpt

Currently, there is a grid section on the homepage of our site showcasing the two most recent blog posts. I am looking for a Javascript solution to relocate the date to the bottom of each block, outside of the border. For reference, you can visit the follo ...

The Zurb Foundation grid system is causing issues when trying to implement vertical tabs

My vertical tabs are giving me trouble when I try to nest grid or block elements, causing everything to overflow outside the element. For example, in the image below, the numbers 1,2,3 should be in the right section. <div class="row"> <div class ...

The bottom margin of the last element does not affect the size of its container

I'm curious as to why the margin-bottom of .content-b isn't affecting the height of the .container. .container { background: grey; } .content-a, .content-b { height: 100px; border: 1px solid red; margin-bottom: 100px; } <div class= ...

Tooltips experience issues when interacting with elements that do not utilize the :active state

$(function () { $('[data-toggle="tooltip"]').tooltip() }) <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" ...

The WebView.HitTestResult method is currently only receiving <img src> elements and not <a href> elements

I am attempting to open a new window in the Android browser using "_blank". I have set up an event listener for this purpose. mWebView.getSettings().setSupportMultipleWindows(true); mWebView.setWebChromeClient(new WebChromeClient() { ...

The AJAX data variable fails to send to PHP script although $_POST is defined

I am at my wit's end with this problem. I am attempting to send a variable to a PHP script using AJAX, and although I can confirm that $_POST is set, the variable remains undefined. Oddly enough, I have used almost the same code in other instances an ...

Just starting out with Java EE; any tips on structuring a service or daemon?

I am completely new to the world of Java EE. As a way to familiarize myself with Java EE, I have been attempting to develop a tiered web application. However, I am facing some challenges when it comes to setting up a background service that can perform tas ...

Displaying Hierarchical Data with AngularJS and ng-repeat

Recently, I've been working on finding an elegant solution to represent hierarchical data in my application. Specifically, I have implemented a slide effect for bootstrap badges that showcase sub-categories using AngularJS. With some guidance from th ...

Exclusive workshop on concealing H1 header in Jumbotron

Trying to make a Jumbotron's height 100% of the user's browser window with a special class, but running into issues on mobile devices as a div within the jumbotron is covering up the headline. Any suggestions for a fix? Live link: HTML <di ...

Tips for interpreting nested JSONs for aggregation purposes?

I am a novice when it comes to using Spark. My main objective is to handle nested JSONs and organize them based on specific criteria. For instance, if the JSON includes information about individuals like their city and zip code, I aim to group individuals ...

Are there any "Undefined" tabs hiding in your RMarkdown tabsets?

After knitting my RMarkdown document to an HTML file, I noticed that the tabs appeared as shown below: https://i.sstatic.net/x1p70.png However, when I save and share the document with my audience, I encounter an issue where these tabs are labeled as "und ...

Extract the content of a textbox within an iframe located in the parent window

Is it possible to retrieve the value of a text box in an iframe from the parent page upon clicking a button? Below is an example code snippet showcasing the situation: <div> <iframe src="test.html" > <input type=text id="parent_text"> & ...

Triggering an automatic pop-up window using JavaScript based on a PHP condition

I have developed a hidden pop-up box that becomes visible when targeted, with its opacity increasing to one. I am aiming for the pop-up to appear if the user is identified as a "firstTimeUser," a status saved in a PHP $_SESSION variable. However, I am stru ...

Unraveling the mystery of decoding a flattened Json structure

I am tasked with using a flattened structure JSON, like the following hierarchical Json example: { "employees": [ { "employee1": { "employeeId": 123, "name": "ABC", "type": "permanent", "address": { "s ...

Display information in a detailed table row using JSON formatting

I have set up a table where clicking on a button toggles the details of the corresponding row. However, I am having trouble formatting and sizing the JSON data within the table. Is there a way to achieve this? This is how I implemented it: HTML < ...

Guide to invoking a jQuery function by clicking on each link tab

Below is a snippet of jQuery code that I am working with: <script> var init = function() { // Resize the canvases) for (i = 1; i <= 9; i++) { var s = "snowfall" + i var canvas = document.getElementById( ...

Ways to avoid overflow of dynamically added div element?

Currently, I am facing an issue while dynamically appending div elements with the .magnet class to my page. These elements end up overflowing the container boundaries and I am struggling to find a solution for this problem. If anyone could check out my j ...

What is the process for configuring the Java path within Eclipse in order to execute it from an external drive?

Currently, I have Eclipse 3.5.1 and the Portable Java (obtained from Portableapps.com) set up on a portable hard drive. I'm looking to direct Eclipse to utilize the portable Java version, enabling me to run Eclipse on any computer without Java being p ...