1

project structure

In intellij IDEA, I started a new Java Web application and I am using servlets to handle GET and POST requests, now the problem comes in where I introduce CSS and JS in my JSP pages, they seem not to be rendered/ pulled from the sources and when I inspect the code in browser and click on the href or src links, I am redirected to the servlet error page, with this code

<!doctype html><html lang="en"><head><title>HTTP Status 404 – Not Found</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 404 – Not Found</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> &#47;post&#47;MIS&#47;assets&#47;css&#47;contracts-list.jsp</p><p><b>Description</b> The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.</p><hr class="line" /><h3>Apache Tomcat/8.5.43</h3></body></html>

from my research I changed my links from

<link href="assets/css/style.css" rel="stylesheet">

to

<link href="${pageContext.request.contextPath}/assets/css/style.css" rel="stylesheet">

But the same problem (redirect to servlet errror page) still persists

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css">
    <!-- Bootstrap core CSS -->
    <link rel="stylesheet" href="${pageContext.request.contextPath}/assets/css/bootstrap.min.css">
    <!-- Material Design Bootstrap -->
    <link href="${pageContext.request.contextPath}/assets/css/mdb.min.css" rel="stylesheet">
    <!-- Your custom styles (optional) -->
    <link href="${pageContext.request.contextPath}/assets/css/style.css" rel="stylesheet">

    <!-- MDBootstrap Datatables  -->
    <link href="${pageContext.request.contextPath}/assets/css/addons/datatables.min.css" rel="stylesheet">
<script type="text/javascript" src="${pageContext.request.contextPath}/assets/js/jquery-3.4.1.min.js"></script>
<!-- Bootstrap tooltips -->
<script type="text/javascript" src="${pageContext.request.contextPath}/assets/js/popper.min.js"></script>
<!-- Bootstrap core JavaScript -->
<script type="text/javascript" src="${pageContext.request.contextPath}/assets/js/bootstrap.min.js"></script>
<!-- MDB core JavaScript -->
<script type="text/javascript" src="${pageContext.request.contextPath}/assets/js/mdb.min.js"></script>
<!-- MDBootstrap Datatables  -->
<script type="text/javascript" src="${pageContext.request.contextPath}/assets/js/addons/datatables.min.js"></script>

I expect the page to render linked css and JS files but this redirects to servlet error page

1
  • Your problem is not reproducible based on the information provided so far. The cause of your problem is somewhere else which you didn't include in the question. Provided that EL expressions work fine, I would guess a badly configured custom servlet or perhaps filter who is incorrectly taking over the job of the default servlet (as that's the one responsible for serving static assets). To start, post a list of all servlet/filter configuration, especially URL patterns. Or, simply analyze and fix yourself by disabling them all and then re-activating one by one until the problem reappears. Commented Sep 9, 2019 at 15:28

1 Answer 1

1

By Analysing Your error,

HTTP Status 404 – Not Found ****** /post/MIS/assets/css/contracts-list.jsp

I got your problem,
1. You are not reading error messages sent by your intellij server.
2. Two mistakes in URL. a. context path /post/MIS but instead it should be /MIS b. assets/css/contract-list.jsp, I guess you are doing mistake while including your JSP(forwarding to JSP or redirecting to JSP).

There is nothing relation to css path to your 404 error. As css and js files loads after your jsp loads. Main entry only 404. Fix including contract-list.jsp, Rest of the things will work definitely.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.