Include html file uploaded by user - java

This it what I would like to do: A user uploads a bunch of html files as a zip archive. I unzip that archive and display the html content on the website.
For that, I would like to include the html content into a thymeleaf page. I have tried this so far:
<div th:include="http://localhost:8181/MySpringApp/uploads/include.html"></div>
<div th:include="#{/uploads/include.html}"></div>
<div th:include="#{~/uploads/include.html}"></div>
In all three cases I get the following error (with varying URL):
Exception processing template "dashboard": Error resolving template "/uploads/include.html", template might not exist or might not be accessible by any of the configured Template Resolvers (dashboard:40)
How would I get this to work? I have only seen examples of including static files from the template folder. But that's not what I would like to do.
I am using Wildfly 9 and in the standalone/data folder I have created the uploads folder.

The code like this should work:
<div th:include="#{/uploads/include}"></div>

Could it be a permisson issue? I'm just wondering because you say that some external user can uploads those files, so you might not have the right permisson to display or use them.
Hope it helps!

Assuming that your uploads folder is under templates, insert the HTML as:
<div th:insert="~{uploads/include}"></div>
Btw, th:include is not recommended since Thymeleaf 3.0.

Related

Failed - No file

I am new in Tomcat Server as well in Java as I take over code from other developer. I attached pdf file in web pages to be download from footer section. The footer was from another directory inside webapps ROOT/WEB-INF/../../contactUs.jsp and the file is in webapps/brochure.pdf so I called the pdf file and it display into web page but when I download then it say "Failed - No file"
src:
<aside class="widget widget_footer">
<h4 class="widget-title">Company</h4>
<ul class="ps-list--link">
<li>About Us</li>
<li>Career</li>
<li>Contact</li>
<li><a href="${pageContext.request.contextPath}/brochure.pdf" download>User Guide</a></li>
</ul>
</aside>
Thanks for corresponding my question in advance.
I want to the file to be downloadable for client.
The paths you mention look strange:
ROOT/WEB-INF/../../contactUs.jsp would mean contactUs.jsp is besides ROOT?
webapps/brochure.pdf would mean brochure.pdf is besides ROOT as well?
This is not where Tomcat would serve files, and your error message is likely related to that.
In the webapps directory you should have different web applications - each of them in either a directory or the zipped version, a .war file. ROOT is just a web application specially treated by Tomcat. Inside a webapp you can find content to be served directly, just like a htdocs directory on a webserver installation - or the special directory WEB-INF, which contains internal data not directly presented on the network.
So assuming your webapp's name is ROOT, place your pdf into the path webapps/ROOT/brochure.pdf and reference it as /brochure.pdf from JSP pages. Hint: it should reside in the same directory as about-us.jsp.

Convert a simple html file to scorm package

I want to host my html asset into LMS, here LMS only accept and run the SCORM Package.
How can i convert an html file (exporting from my app using jasper report) to a scorm package?
Any help?
For single pages, in fact the best approach I found was to do it mannually: based on: https://www.ispringsolutions.com/blog/how-to-convert-html-to-scorm to adapt it, just ignore the res folder and point to the index on: <resource identifier="resource_1" type="webcontent" adlcp:scormtype="sco" href="index.html">
Download a SCORM example: https://21w98o3yqgi738kmv7xrf9lj-wpengine.netdna-ssl.com/wp-content/assets/golf_examples/PIFS/ContentPackagingSingleSCO_SCORM12.zip
extract it;
in imsmanifest.xml change the title to your title;
List all the resources that your HTML page includes;
Zip the course root folder (with the manifest file).
On this page you will find software that you can use to create SCORM compatible packages. If you have created a simple project, you can unpack the resulting ZIP file and edit the content. Mostly you will find an index.html there. I know, that sounds a bit awkward at first.
https://docs.moodle.org/35/en/Creating_SCORM_Content

linking dynamic .html form to .jsp

i am new to advance java and trying to build a dynamic web application using eclipse. I have no idea how to link a ready-made/dynamic .html form with .jsp , although i have made a registration form in jsp but it is not looking nice.
One way to convert an HTML file to a JSP is to open a new JSP file ( in your IDE ) and copy - paste the contents of the HTML file into it. Another way is to embed the Java code into the HTML file then change the file's extension from a .html to a .jsp.

Can a .vm(velocity template) file included inside an HTML fILE IN Spring

Is there any way to include an .vm file inside the .HTML file and return the .HTML file as the view in spring, I have seen example where the whole HTML changed to .vm and used as view. But I would like only one page to be changed as .vm with all other files still uses .HTML extension, is this possible in spring, could you please suggest
Regards
Vivek

It's possible to upload a image which is not located in eclipse project to a jsp

Is there a way to upload an image not located in Eclipse project to a jsp?. I have searched that it is possible if image directory is placed in Application Server but that's not what I want, I would like to use a c:\directory in Windows 7. Please find below the code in jsp file I'm using:
<body>
<h1>Image below:</h1>
<img alt="No Image"
src="C:/MauricioFiles/Proyectos_JavaEE7/MusicStore/pics/guitar.png"
width="100" height="100">
</body>
Thank you!!!
The <img src> must refer a public web URL, not a local disk file system path. Your images have to be available by a HTTP request. It's namely the webbrowser who has got to download them, not the webserver who has got to include them somehow.
Yes you can upload it. But I think what you want to do is to access the local file without uploading it.
But as JSP says, JavaServer Pages. That means that you need to have all your files uploaded and ready in your server. What you do at the moment is, that you use a file which is on your computer and not inside your Server-directory. But you can't access local files outside of your server-environment.

Categories