So far, you’ve run a server using Tomcat or Jetty. You deployed a “hello world” web app to your server, and you’ve visited that web app by navigating to localhost:8080 in your web browser.
For a webapp on a Tomcat server, if I change the index.html file then I can view the changes immediately after I refresh the page on my browser.
But when I modify the response by the servlet class and compile it (while keeping the server running), then after refreshing the URL on my browser I don’t see any change until and unless I restart the server.
If I had to guess, I’d say that’s because the server loads the Java classes at startup (or the first time they serve a request), and then they keep those classes in memory from then on, without reading from the .class files again. However, I would guess that static files like index.html are loaded from the file system every time they’re requested.
If you want your Java changes to be reflected, you might look into something called “hot reloading” or “hot swapping” which tells your server to reload your classes whenever the files change. I personally tend to restart my server manually, or I use an IDE to handle this stuff for me.
I was having this error on both Tomcat and the jetty Server.
I was having trouble including the css and javaScript files into my index.html ( I had them all placed together inside the webapps/myWebAppName/ directory).
Ignore the temp folder !!
This worked fine when I opened the index.html directly in the browser. i.e. the css and js worked fine.
But when I placed the css and js files in a separate directory and then included them in the index.html file, everything worked fine even for the Tomcat & Jetty server case.
Wheneve I toggled between the above two lines or did something similar (i.e. whenever I changed the src), I used to get the Uncaught ReferenceError: load is not defined at onload.
Where, load was a function defined inside the “versus.js” file.
Ahh yeah that makes sense, this happens to me all the time. It’s because your browser is caching your HTML file, so it’s still trying to load the JavaScript file from the old location.
I’ve gotten into the habit of always using a cache-clearing refresh automatically whenever I’m doing web dev stuff, because of this exact kind of issue.