Insert template located anywhere in filesystem in Pebble template - java

I have a Spring Boot Java Web application.
The application can generate web pages using Pebble.
All resources used by Pebble are located in application.war\WEB-INF\classes.
Then, in the Pebble engine gets the template. In this template, I need to include a css that can be anywhere in the filesystem, e.g.:
<html>
<head>
<style>
{% include "/absolute/path/of/custom-css.css" %}
</style>
</head>
<p>{% include "this/works/because/foo/is/under/WEB-INF/classes/foo.html" %}</p>
</body>
</html>
I cannot get the custom-css.css to be included. Error is com.mitchellbosecke.pebble.error.LoaderException: Could not find template
I can't find any help in documentation (https://pebbletemplates.io/wiki/tag/include/) nor here (https://groups.google.com/forum/#!topic/pebble-templating-engine/2gK9B1twwKw)
Any idea ?

I found the issue. My engine was initialized with the classpathloader only instead of the default classpathloader AND fileloader.

Related

CSS JS and Links not loading when deploy Spring boot as war in Tomcat

I have a Spring boot web application, it works fine when running as executable jar, but when I build as war and deploy to Tomcat, the css, js files are not loading and looking into further, I found out all links are pointing to root context path "/", I tried changing base href = "./" this fixed the problem of loading css and js, but I need to do that in lot of pages.
Also the links in <a> still points to root context path and to make this work I need prefix'./' . Below are my code snips,
CSS and JS link
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/signin.css" rel="stylesheet">
<script src="js/popper.min.js"></script>
<script src="js/bootstrap.min.js"></script>
Tag
<a class="topHeader" href="/activateAccount"></a>
Is there a shortcut to fix this problem or should I change <base href> and <a href> in all the pages? Any help is highly appreciated.
There is no short cut or quick fix for this, I removed "/" in links in all anchor tags and that worked for me.
Example
<a href="/resetPassword" style="float: right;">
changed to
<a href="resetPassword" style="float: right;">

How to increase client_max_body_size for a Spring Boot application on Elastic Beanstalk?

I've created my Spring Boot application .jar file using Gradle's build/bootJar and then deployed it to Elastic Beanstalk. But when I do a POST request with large data I get the following error message:
<html>
<head>
<title>413 Request Entity Too Large</title>
</head>
<body bgcolor="white">
<center>
<h1>413 Request Entity Too Large</h1>
</center>
<hr>
<center>nginx/1.14.1</center>
</body>
</html>
I've tried adding client_max_body_size 50M; to a myconf.conf file which is located {project_root}/.ebextensions/nginx/conf.d/myconf.conf and rebuild and redeploy the .jar file but this does not work.
I've also tried moving that same .ebextensions folder {proejct_root}/src, that does not work either.
Anything else I can try? I wonder if creating the .jar using bootJar is the correct way.

CSS not loading in spring boot application

I have been searching all day, moved the style.css everywhere and still not managed to get it loaded. The images wont load as well.
My structure:
But if i click the firefox button, it loads:
This is how the style.css is imported in the head of the index:
(tried all kind of combinations)
When i check the developer tools, it says 404 for GET request (style.css and the pictures)
Spring Boot knows where the static directory is, so you don't need to use the ../ technique to get to the files within. The other part is that you should be using an annotation to get there. It may depend on what view template you are using, but for thymeleaf this is how you would achieve pulling in the css file:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<title>Your Title</title>
<link rel="stylesheet" th:href="#{/css/style.css}" />
</head>
Notice the annotation in th:href="#{/css/style.css}"
Make sure you include the namespace of your view template, th in the example.
Images work the same way:
<img th:src="#{/img/stanev2.png}" />

JSP Tomcat7 static css and js files not loading

Learning JSP and have an issue with the css/js content not loading. I have a jsp page, where I have bootstrap css and js referenced using standard html link and script tags:
<link rel="stylesheet" type="text/css" link="/bootstrap/css/bootstrap.css" />
and
<script src="/WebIntro/bootstrap/js/bootstrap.js"></script>
neither of them work and Chrome is giving me the following on the console:
Resource interpreted as Stylesheet but transferred with MIME type text/plain:
If I use an include directive, it works for the css but pulls all the content into the file:
<%#include file="/bootstrap/css/bootstrap.css"%>
The jsp has the following #page and meta tags:
<%#page contentType="text/html" %>
and
<meta http-equiv = "Content-Language" content = "en"/>
<meta http-equiv = "Content-Type" content="text/html; charset=utf-8">
I tried googling and found the mime-mapping element for the web.xml but the following seems to have no affect:
<mime-mapping>
<extension>css</extension>
<mime-type>text/css</mime-type>
</mime-mapping>
<mime-mapping>
<extension>js</extension>
<mime-type>application/javascript</mime-type>
</mime-mapping>
If there is some standard Tomcat config that needs to happen I am unaware as I am new to Tomcat; using Tomcat 7, and eclipse and this is in a maven project.
The solution for me was very strange. The changes to the web.xml file that was present since I built the project in eclipse/maven, weren't reflected in the web.xml within tomcat webapp application directories. Everything else in the package updates fine (as far as I can tell), except for the web.xml?
So I found the web.xml file within eclipse inside target >> project-SNAPSHOT >> WEB-INF >> web.xml (which is supposed to be derived). Forced changes there and it worked, changes were picked up and my original issue gone.
I am guessing I had inadvertently broken some type of dependency link or something along the way somehow, but once I added the servlet, mappings, etc back in, everything worked fine.
Weird.
Removing this line in jsp resolved the error for us.
We were facing the issue when using Tomcat 8.5.59

HTML embed not working for Java Applet

I've been researching on which to use between <applet>,<object>, or <embed>, but none seem to work.
When I tried to load JApplet through HTML I am got RuntimeException error java.lang.NoClassDefFoundError: com/sforce/ws/ConnectionException.
When I tried to run number1.class with the number1.class being in myfile.jar it needs the other 3 jar files for the library and that is what the error is. The files look like this:
tomcat-->webapps-->applet-->newhtml.html
applet-->lib-->(wsc-23,enterprise,partner)
applet-->applet_class-->(number1.class,myfile.jar)
Any help would be appreciated.
I've also looked through majority of stackoverflow questions as well as other places, but still no luck!
<!DOCTYPE html>
<html>
<body>
<html type="application/x-java-applet;version=1.6"
width="512" height="512"
code="applet_class.number1.class"
src="myfile.jar,applet/lib/wsc-23.jar,
applet/lib/enterprise.jar,
applet/lib/partner.jar"/></html>
</body>
</html>
The best way to deploy a JWS app. or applet is to use the Deployment Toolkit Script.
But looking at that element..
<html type="application/x-java-applet;version=1.6"
width="512" height="512"
code="applet_class.number1.class"
src="myfile.jar,applet/lib/wsc-23.jar,
applet/lib/enterprise.jar,
applet/lib/partner.jar"/></html>
The most basic form of the applet element (deprecated in HTML 4.01 is):
<applet
width="512" height="512"
code="applet_class.number1"
archive="myfile.jar,applet/lib/wsc-23.jar,applet/lib/enterprise.jar,applet/lib/partner.jar"/>
</applet>
Change html to applet.
Remove the type attribute.
Remove the .class from the end of the code attribute.
Change src to archive, and have all the archives in one line.

Categories