Thymeleaf fails to load resources - html

Hello i'm trying to render my html page with thymeleaf but it fails to load the .js file. I'm using spring-boot and my file structure is src/main/resources/templates this contains all my html files. My css files are located in src/main/resources/static/css/. My .js files are located in src/main/resources/js/.
Now i tried rendering my guest.html file but it's failing to load resources as i tried inspecting the element on chrome and it displays error message below:
http://localhost:8080/js/bootstrap-formhelpers.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8080/js/bootstrap.min.js Failed to load resource: the server responded with a status of 404 (Not Found)
Below is the issue in my guest.html file that fails to locate the resources:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js" th:src="#{https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js}" ></script>
<script src="../js/bootstrap.min.js" th:src="#{js/bootstrap.min.js}"></script>
<script src="../js/bootstrap-formhelpers.min.js" th:src="#{js/bootstrap-formhelpers.min.js}"></script>

Spring Boot does not serve static content from src/main/resources by default. It serves content from the following classpath locations:
classpath:/META-INF/resources
classpath:/static
classpath:/resources
classpath:/public
Therefor, src/main/resources/static/css is served, but not src/main/resources/js/.
Move the js directory to the src/main/resources/static directory to have it served. Another option is to add a resource handler:
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/js/**")
.addResourceLocations("classpath:/js/");
}
You can also override the spring.resources.staticLocations property.
More information about serving static content with Spring Boot can be found in the Spring Boot Documentation: Static Content.

Related

Flutter App to Web through Github pages blank screen

I have a page generated by Flutter-Web shops and it is a blank page. And I have an error in the console. This happened after uploading the build web of Flutter into GitHub Pages.
Uncaught (in promise) TypeError: Failed to register a ServiceWorker for scope ('https://adamtechnologynl.github.io/') with script ('https://adamtechnologynl.github.io
/flutter_service_worker.js?v=2470069411'): A bad HTTP response code (404) was received when fetching the script.
manifest.json:1 Failed to load resource: the server responded with a status of 404 ()
manifest.json:1 Manifest: Line: 1, column: 1, Syntax error.
manifest.json:1 Failed to load resource: the server responded with a status of 404 ()
(index):88 Failed to load app from service worker. Falling back to plain <script> tag.
(anonymous) # (index):88
(index):47 GET https://adamtechnologynl.github.io/main.dart.js net::ERR_ABORTED 404
loadMainDartJs # (index):47
(anonymous) # (index):91
I found the solution. This happens when you have put it another directory instead of the root of the GitHub.
So my code is in "https://username.github.io/demo/book-king/belasting-web-v1/" so that last part we should append everything after "https://username.github.io/" also in the index.html. You can solve it by modifying the line (number 17 by me):
Change:
<base href="/">
into:
<base href="/demo/book-king/belasting-web-v1/">
And then you are done.
This solution works. But for me, line no 17 was not <base href="/">.
It was like this <base href="$FLUTTER_BASE_HREF">. Given that FLUTTER_BASE_HREF is a variable, it can be modified.
How?: Provide --base-href argument to flutter build like below
HostingURL : https://<github_user_name>.github.io/project_aj/demo/gh-pages/
Apart from the https://<github_user_name>.github.io should go as the value for --base-href
flutter build web --base-href=/project_aj/demo/gh-pages/

CAS 5.3.1 and random 404

We are randomly redirected to domain by CAS and end up in 404 response. We thought to create static 404 error page. But problem is CAS has embedded tomcat which is responsive to domain.com/cas context-path. And we want error page on domain.com/.
How can I achieve that?
Related post I created: Spring boot multiple contexts - one for public error
But problem is CAS has embedded tomcat which is responsive to domain.com/cas context-path. And we want error page on domain.com/.
Spring Boot applications that use an embedded tomcat container only respond to requests mapped to the context-path, which in your case is /cas. There is no such thing as "/" or ROOT when dealing with an embedded container.
So you'll need to either use an external tomcat instance, or change your context-path to "/".

Where is Couchbase Sync Gateway AdminUI?

I have already set "adminUI": "0.0.0.0:4985/_admin/" in my config. I still get 404 page not found when going to the endpoint (e.g. http://<host IP>:4985/_admin/).
This is the description of the config line adminUI from http://developer.couchbase.com/documentation/mobile/1.2/develop/guides/sync-gateway/configuring-sync-gateway/config-properties/index.html
URL of the Sync Gateway Admin Console HTML page. The default is the bundled Sync Gateway Admin Console at localhost:4985/_admin/.
I got this hint from https://github.com/couchbase/sync_gateway/blob/aba088a902b162bcaed745510f4d012b8908a303/rest/config.go#L64
AdminUI *string `json:",omitempty"` // Path to Admin HTML page, if omitted uses bundled HTML
I omitted the line "adminUI": "0.0.0.0:4985/_admin/" from the config file to get the bundled Couchbase Sync Gateway Admin UI HTML page.

Graphhopper - java.lang.IllegalStateException: Call load or importOrLoad before routing

I have developed and API which uses Graphhopper, and deployed it on a test server. I tested it and it works correctlty.
The problem is that when uploading the same project to another server, when I make an API request it crashes, showing this error:
java.lang.IllegalStateException: Call load or importOrLoad before routing
I put the same files in both servers:
"map" folder containing "spain-130901.osm.pbf" file
"data" folder containing this files:
properties
nodes
names
locationIndex
geometry
edges
So, what could be the problem? It crashes in one server and works well in the other one...
Finally the problem was related with permissions.

Application Cache works in Tomcat 6.0 but not in weblogic 10.3

I'm working with application cache and I'm facing the below issue:
In Tomcat Server:
When the server is online and if the page is accessed for the first time, the files specified in the manifest file are caught successfully in the application cache.
When the server is offline, when we try to access the cached page, there is an error in the browser console (Application Cache Error event: Manifest fetch failed (-1) which is quite normal as per my findings in the internet) but the application cache works fine.
In Weblogic server:
I tried to run the same code in Weblogic server, in online mode, the files are cached as expected. But in the offline mode, for the first time the page is loaded, it works fine, but when I see the console the status of the application cache goes to OBSOLETE mode and so if I do a refresh of the page again, it throws me a 404 error. Also, I'm not getting the "Application Cache Error event: Manifest fetch failed (-1)" which I get when I try to run the code in tomcat server. Please let me know what's that I'm doing wrong. Below are the files:
index.html
<html manifest="demo.appcache">
<head>
<link rel="stylesheet" href="style.css" type="text/css" />
<script type="text/javascript" src="script.js" ></script>
</head>
<body>
<h1>Basic example of page using Application Cache</h1>
<p>Disconnect from the internet and try to reload this page. It should load without requiring you to connect to the internet.</p>
</body>
</html>
manifest file (demo.appcache)
CACHE MANIFEST
CACHE:
style.css
script.js
index.html
demo.appcache
NETWORK:
*
style.css
body{
background-color: #333;
}
h1{
color: #c94054;
}
p{
color: #fff;
}
script.js
if (!window.applicationCache){
alert('It seems that Application Cache is not supported in this browser. Please use a browser which supports it.');
}
web.xml
<mime-mapping>
<extension>appcache</extension>
<mime-type>text/cache-manifest</mime-type>
</mime-mapping>
This problem comes when the browser encounters the manifest line in the html tag, it tries to download the appcache file from the server. But when the server doesn't have this file it returns 404 error, so the application cache goes to OBSOLETE event.
So in this case, the possible reasons are
1- your server doesn't contain this file
2 - If your server has this file but not returning to the browser, this happens when the server is running but your application is actually undeployed.
So try stopping your server rather than just undeploying your applciation from the server instance.
Hope it works.