0

i have external java-script and CSS file in my project where i am defining my JS and Styling code, i am calling them through src but the browser console says that Loading failed for the <script> with source “http://localhost:8080/TPWebReport/JS/Javascript.js”

here is my code Structure

Code Structure

this is how i am doing it

    <link href="./css/style.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="JS/Javascript.js"></script>

link is calling in head tag

script is calling in end of body tag tag

  • I am using Eclipse 2018-09 version
  • @cale_b it is not TPS Report it is TPWebReport which is my project name..and what was that link ? –  Dec 10 '18 at 13:12
  • "http://localhost:8080/TPWebReport/" Are you sure your local server is well setup to ping the right root forlder? – Richard Dec 10 '18 at 13:17
  • @vincent-decoplus yupp ..but,can i check my local server is well setup or not –  Dec 10 '18 at 13:19
  • @dheerajkumar Yes that's very simple, click on this "http://localhost:8080/TPWebReport/" if it lands on something, it means it's well made. If not, send us the error – Richard Dec 10 '18 at 13:23
  • @vincent-decoplus on to my console ? –  Dec 10 '18 at 13:25
  • no, the message in the middle. If it's "can't reach the server" something like this, you have to redo/verify your server param – Richard Dec 10 '18 at 13:27
  • @vincent-d yeh it is redirecting me to my login page –  Dec 10 '18 at 13:29
  • Ok, so it's not the problem, sorry we had to check ^^ – Richard Dec 10 '18 at 13:31
  • What happens if you try to access the file directly by navigating to the url of the javascript file? – Patrick Dec 10 '18 at 13:32
  • I was about to ask the same. Can you click on that please http://localhost:8080/JS/Javascript.js – Richard Dec 10 '18 at 13:33
  • @vincent-d http://localhost:8080/TPWebReport/JS/Javascript.js * – Luca Antonelli Dec 10 '18 at 13:34
  • @vincent-d `HTTP Status 404 – Not Found` this i got –  Dec 10 '18 at 13:34
  • @dheerajkumar have you trien Antonelli link or mine? – Richard Dec 10 '18 at 13:35
  • @vincent-d on clicking http://localhost:8080/TPWebReport/JS/Javascript.js and http://localhost:8080/JS/Javascript.js i am getting `HTTP Status 404 – Not Found` –  Dec 10 '18 at 13:38
  • try both without the ports ":8080" – Richard Dec 10 '18 at 13:39
  • Are you hosting your files from the `dist` folder or are you serving the files from the root folder of the project? Can you see in your web server logs if you are accessing the correct file? – Patrick Dec 10 '18 at 13:39
  • @Patrick how can i check that? –  Dec 10 '18 at 13:41
  • Check your logs? I don't know; what web server are you using? It's your machine, you tell me ;) – Patrick Dec 10 '18 at 13:42
  • @vincent-d without portno it is redirecting me to my stackoverflow question –  Dec 10 '18 at 13:42
  • @Patrick web server log means on my browser console? –  Dec 10 '18 at 13:44
  • @dheerajkumar what?! o_o How? You tried localhost/TPWebReport/JS/Javascript.js and localhost/JS/Javascript.js ? And it goes to stackoverflow? I'm speechless lol – Richard Dec 10 '18 at 13:44
  • What browser are you using? – Luca Antonelli Dec 10 '18 at 13:45
  • @vincent-d ohh sorry its says `Unable to connect` –  Dec 10 '18 at 13:45
  • No, not in your browser. In order to serve javascript files you need a web server. How are you running your project? – Patrick Dec 10 '18 at 13:45
  • @L.Antonelli mozila developer version –  Dec 10 '18 at 13:45
  • @dheerajkumar please, try with another web browser – Luca Antonelli Dec 10 '18 at 13:46
  • @Patrick using tomcat 9 i am running on server –  Dec 10 '18 at 13:46
  • oooh.. That's why :o when we asked if you have well setup your server it was underline. You need a webserver (you can use wamp or lamp or mamp or anything easy to configure) – Richard Dec 10 '18 at 13:47
  • @L.Antonelli what should i try the link or to run my application on diff browser? –  Dec 10 '18 at 13:47
  • Okay, so check the logs of tomcat. How is that serving your files? And from what folder? Is the css file loaded? What files are in your build folder? – Patrick Dec 10 '18 at 13:48
  • @vincent-d no but previously i was using eclipse mars and this was working fine there –  Dec 10 '18 at 13:48
  • @dheerajkumar try first with the link – Luca Antonelli Dec 10 '18 at 13:48
  • @L.Antonelli same on the other browser i.e on crome it shows not found –  Dec 10 '18 at 13:49
  • According to [this post](https://stackoverflow.com/questions/202253/eclipse-tomcat-how-to-specify-which-folder-is-served-from-the-project) tomcat serves files from the WebContent folder. Try moving the JS folder and css folder in to that folder – Patrick Dec 10 '18 at 13:51

1 Answers1

2

You said using <script src="./JS/javascript.js></script> didn't work, so I would double check that your root folder and the code match i.e. double check capitalization/name.

I would also recommend trying to move the js file to a new folder and seeing if that fixes the issue.

Malmadork
  • 237
  • 4
  • 13
  • you saying to create another folder with diff name just like i have created JS –  Dec 10 '18 at 17:02