• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

JSP - CSS file and JS files aren't loading at all

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm unable to load js and css files in JSP file. In desktop it runs as `http://localhost/` but in server it will run as `http://localhost/myapp/`. How can I ensure it works everywhere?



   GET http://localhost:8080/js/jquery.min.js net::ERR_ABORTED 404 (Not Found)
   
   GET http://localhost:8080/css/bootstrap.min.css net::ERR_ABORTED 404 (Not Found)

In head Head tag I have this..

<script src="/js/jquery.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css"  href="/css/bootstrap.min.css">

Edit: I tried the following and it's still not working..




Edit: even tried the following as suggested in this https://www.codejava.net/frameworks/spring-boot/how-to-create-a-spring-boot-web-application-spring-mvc-with-jsp-thymeleaf




 
Bartender
Posts: 7645
178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nothing that is inside WEB-INF will be served directly to the client. You need to move JS and CSS (and everything else directly accessed by the browser, like images) to a directory outside WEB-INF.

The configuration in application.properties is only for JSP pages.
 
Sheriff
Posts: 67759
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Additionally you'll need to precede all paths with the context path of the application. It can be obtained in a JSP with the EL expression: ${pageContext.request.contextPath}
 
Ranch Hand
Posts: 1056
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Bear,

I am facing the problem using Tomcat server 10.1.34, I have included the


but when i rendered the jsp page on the browser, it is still giving me 404.

What can I do ?

Unfortunately, the copy that is working is saved in a hard disk that is 'spoilt' ....
 
Can't .... do .... plaid .... So I did this tiny ad instead:
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic