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.
Related
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 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
I want to have an image as part of my apk that the user can modify using my app.
I dont want to save it on the SD card. It should not be viewable or editable outside the app.
Where do I need to put the original image, the one I include to be used by default?
In the resources drawble folder? Or the assets folder?
And how do I overwrite that image with a user-generated one? (with the idea that this will be used in the app everywhere instead.)
You cannot overwrite resources not assets contents.
Alternative solution:
What about saving it to the internal directory of an application, which would not be accessible outside of you application scope? and then every time you display a picture, check if the one in internal memory exists, if it does, then display that one instead of the one in drawables
docs: http://developer.android.com/guide/topics/data/data-storage.html#filesInternal
You can save files directly on the device's internal storage. By
default, files saved to the internal storage are private to your
application and other applications cannot access them (nor can the
user). When the user uninstalls your application, these files are
removed.
I'm trying to upload images in JSP using Apache Common FileUpload with Spring/hibernate. Uploading of images works well.
My project folder is located by the following path.
E:\Project\SpringHibernet\wagafashionNew\wagafashion
After parsing the request, I'm trying to save the uploaded image into the following folder.
E:\Project\SpringHibernet\wagafashionNew\wagafashion\web\images
I've tried in various ways to get this path but I couldn't succeed.
Specifying a relative path something like the following
File f=new File("wagafashion/web/images/image_file.xxx");
would not work.
Is there a way to retrieve the following path?
E:\Project\SpringHibernet\wagafashionNew\wagafashion\web\images
or specify a relative path with the new File("relative_file_path") constructor?
Am I saving files into a wrong directory? In that case in which project folder files are to be saved?
Maybe.
One way it to ask the the ServletContext to getRealPath("/web/images"), and see if that returns something -- it doesn't have to, but it likely will. If it does, then you can put the images there.
However.
If you're deploying like most folks using a WAR, then all of those images will Go Away as soon as you redeploy, as most containers take the WAR to be deployed and explode it on to the file system. Whatever was in the directory before you did this (i.e. the code and artifacts from when you last deployed) will be going bye bye, and so you will "lose" your images.
You can mitigate this by doing a directory deploy, that is deploy an already exploded directory. Then you KNOW where the application is located (since you put it there). Then it's up to you to sync that directory with your new code as you make changes (notably it's up to you to delete old stuff you don't want any more).
Other than that, different containers have different mechanisms for mapping in an external directory in to the application space. Glassfish has the concept of "alternate doc roots" that you can use. This allows you to have a place out side of the deployment where static stuff can live and still be served by the container, but isn't wiped out when you redeploy.
Finally, you can always do that yourself, stream your own images, etc. without relying on the container at all. This way you can put the images on the file system, in the database, in memory, whatever.
I have developed a java 1.4 web application.Application is deployed on jboss(tomcat).
suppose my folder structure is
mainfolder(contains subfolders and jsp pages)
images(contains all of images files)
headerfiles(header files)
javascript(javascript files)
url for website login page is
mywebsite.com/mainfolder/login.jsp
if user types complete url for some static resource
mywebsite.com/mainfolder/images/myimage.jpeg
then he can view image on this url.
I want to stop user to view these resources.What should i do?
is there way some way to specigy pattern of file names which i dont want user to see.
In that case i can specify *.ssi pattern to hide.
If those images are used in your pages, the user will HAVE TO be able to download them to see them.
This is basic HTTP. If you want to download a resource, you need to have access to it.
Preventing your users from accessing mywebsite.com/mainfolder/images/myimage.jpeg will mean you WON'T be able to use this image in your HTML or CSS.
If those files should not be available to the user but only the server, don't publish them by keeping them in a non-published folder.
Anything put under the webapp's WEB-INF directory cannot be directly accessed by the browser.
I want to stop user to view these resources. What should i do?
Honestly, this makes no utter sense. How would the client ever be able to get the static data? You can put those files in /WEB-INF (a non-published folder) to hide them from direct access, but you can never use them in your JSP pages, simply because the client isn't able anymore to directly access it.
I think the biggest misconseption here is that you didn't realize that every image, CSS file, JS file, etc counts each as a fully independent HTTP request. It is not true that the complete website is been hauled by a single HTTP request.