2

In spring-boot application, pointed all css, js, images are in below structure:

enter image description here

JSP page is loading with all css/js/images when the URL is like this http://localhost:8080/request/

But when the URL is like this http://localhost:8080/request/rt/home (css/image/js are not loading).

When I click the url of bootstrap.min.css from view source page, it is showing like below: http://localhost:8080/request/rt/public/css/bootstrap.min.css

"rt" is adding in between the url. How to omit the "rt" from path. so that will get path like http://localhost:8080/request/public/css/bootstrap.min.css

It will load css/js/images Please suggest

2
  • Are you creating JAR or WAR archive? Commented Feb 12, 2018 at 10:18
  • just started development..from eclipse application is running.. Commented Feb 12, 2018 at 10:31

2 Answers 2

2

Without seeing your jsp, according to your statements of how it behaves, I would say that you are declaring your stylesheet and resources reference this way, without starting by a /:

<link href="public/css/bootstrap.min.css" rel="stylesheet">

<script src="public/css/bootstrap.min.js"></script>

This means that the resources are relative to the virtual directory of the url bar of the browser.

You should declare your references this way:

<link href="/request/public/css/bootstrap.min.css" rel="stylesheet">

<script src="/request/public/css/bootstrap.min.js"></script>

To avoid hardcoding the contextpath, you could use:

<link href="${pageContext.request.contextPath}/public/css/bootstrap.min.css" rel="stylesheet">

<script src="${pageContext.request.contextPath}/public/css/bootstrap.min.js"></script>

Whicho would resolve your context name

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

Comments

0

Try this way

<link href="/resources/css/bootstrap.min.css" rel="stylesheet">

or

<link href="${pageContext.request.contextPath}/resources/css/bootstrap.min.css" rel="stylesheet">

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.