• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

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




 
Saloon Keeper
Posts: 7100
165
  • 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: 67590
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}
 
reply
    Bookmark Topic Watch Topic
  • New Topic