I have a non-scalable OpenShift app which uses the jbosseap cartridge and also has MySQL and PhpMyAdmin. I can upload and save image files to folders within the OPENSHIFT_DATA_DIR, e.g OPENSHIFT_DATA_DIR/appimages/uploaded.png but I have not been able to display the uploaded images with the HTML img tag.
There seem to be no way to get a correct path to images uploaded under OPENSHIFT_DATA_DIR. I ssh-ed into the server and found that OPENSHIFT_DATA_DIR, which evaluated to /app-root/data/ (actually /var/lib/openshift/5364c54ce0b8cd80180001f7/app-root/data/ ) was kinda outside the webroot of the app (where the ROOT.war was deployed to) which was /jbosseap/standalone/deployments/ROOT.war
So if the app runs from /jbosseap/standalone/deployments/ how can the app display images stored within OPENSHIFT_DATA_DIR which is /app-root/data/ since /app-root and /jbosseap are siblings of the same parent folder.
I just need to use HTML img tag to display an image uploaded and saved under OPENSHIFT_DATA_DIR e.g /appimages/uploaded.png since using src="/appimages/uploaded.png" for an img tag does not display the image.
One solution could be write a Servlet that would read image from $OPENSHIFT_DATA_DIR and write it to OutputStream. Your servlet would be mapped to /images/* and would serve all images. You can also refer to this question How to configure static resources in jBoss AS 7
Related
I'm working with something called JasperReports, and in my servlet, there's this piece of code:
JasperExportManager.exportReportToHtmlFile(jasperprintobject,"C:\\Users\\user\\Desktop\\reports\\myreport.html");
This creates an html file called myreport.html in the reports folder on my desktop, and it also creates a folder called myreport.html_files containing images that myreport.html points to, also inside the reports folder.
I would like to serve this content to the user.
Unfortunately, it seems that the exportReportToHtmlFile method won't let me put the html file inside WEB-INF.
If I could, I would just do:
request.getRequestDispatcher("/WEB-INF/myreport.html").forward(request,response);
I'm thinking about creating a jsp page that can somehow include the html file inside it and forwarding the user to the jsp page, but I'm not sure how to do this.
This is a dynamic web project in eclipse and I'm using tomcat 8.5
Does anybody have any ideas?
Thanks.
I have a spring web project which basically Test webApp and capture screenshot of pages. The path of the saved image looks something like below:
"\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
\Demo\WEB-INF\Results\Test\1118015800\error\error_ST001_1.jpg"
I am trying to display the saved image on a JSP page and so far success has been elusive. I tried different combination of relative path also I tried to give absolute path but it doesn't work. My image tag looks something like this
<img src="<c:url value="/WEB-INF/Results/Test/1118015800/error/error_ST001_1.jpg" />" />
Does anyone have any idea on displaying the image? Could it be because files are stored inside the .metadata folder of Eclipse workspace that I am not able to display any image?
This is because the WEB-INF directory is special. The web container won't serve files from that location - that behavior is defined in the Servlet Spec.
You can either create a servlet that takes requests from the client, loads images (e.g. using getResourceAsStream()) and streams them back, or move the images to a different place in your web app hierarchy.
I have deployed the war into tomcat 7 Openshift . Everything is fine and its running .Myappp Here is my mapped web application.
I am storing images in the dir webapps->docs->images
But When I upload the image (with UI) it doesnt appear on site and I cant even find where images are stored (I connected using FTP -filezilla )
Where my deployed war file stored ? Do I need to make any changes in my code so to upload in proper dir of Openshift??
Thanks in advance
You should use your OPENSHIFT_DATA_DIR (~/app-root/data) to store uploaded images. However, using Java this presents some challenges. I would recommend that you read through this article (https://forums.openshift.com/how-to-upload-and-serve-files-using-java-servlets-on-openshift), it should help you with dealing with user uploaded images.
I am working on a J2EE application in which I need to save user's pictures. my question is where should I save these pictures ? knowing that I want to use a relative path .
NB : I am using glassfish as server .
The best practice here is to save the image inside your web application under web content (make a separate folder) , in this way you will be able to render images in other browsers also (not just in eclipse default's)
and you need to save the complete path of the image into database.
eg : e:\workspace\projectname\webcontent\pic\image.jpg
NB : never store image in database
I would like to exchange the background image in my JSF application. To do this I want to replace the image file in the WebContent folder on my appliaciton. This there a way to do this during runtime or do I have to look for another solution?
instead of changing files, can not you put all images in webContent and handle in code to which image wants to show?
I had a situation to display images based on users role, so kept role1 and role2 images and handled in code.
If images are coming at run time, keep all images at out side of webapps folder (Somewhere like config) and use the specific image. My suggestion is, don't keep dynamic data in side webapps folder, this will remove once your server restart.