Best way to manage images on jsp web application

Hi,
Am developing a jsp web application, in that project, the user will upload the image files, now I created an image directory in the context root and when the image is uploaded by the user it is saved in the /images directory and the image path is saved in the database. I can display this image using the <img src="images/a.jsp" > tag.
but when I rebuild the project all the images in the /images directory get deleated but the image path is remained in the database, is there any method that I make /image dir outside my project context root so that when I rebuild the project the /images dir can get changed and my project will save images outside the context root that is in the /images dir which is now outside the project context root. and is it possible to display those images using <img src""> tag. because this time my /images dir is at D:/images . what could be the best method or way to handle images with the web application.
any suggestion will be helpfull

Well my friend as per your given case there are to two ways of approaching your problem.
Case 1:
How to save the relevant data ??
.Create a backup folder Workstation on which you are hosting your application where you can store all the uploaded files which is outside the scope of webserver(However we can write a dedicated servlet which can access that file) and make sure we pickup from any the folder path from a specfic MessageResource bundle or an context/servlet init parameter in web.xml.
.Write a Upload servlet/Backing Bean which saves all the files in the discussed folder using utility packages like Commons FileUpload,Oreilly MultipartRequest & etc and then register saved fileName in the database user specfic table specific to user.
How to display the Image ??
.Write a dedicated servlet which can pickup user related fileName specfic information from the database and the read the file from backup folder by constructing the path from the entry made as a init param in web.xml or any other custom MessageResource bundle and then stream the Image data using the ServletOutputStream.
NOTE: do not forget to pickup & setImage file ContentType & Set the content length.
.Just try to render the JSP view file where we are displaying the displaying the images by calling the dedicated ImageServlet.
<img src="ImageServlet?userid=2345" align="center"/>Try to refer below posts to get a better understading.
Dedicated Image Servlet:
http://forum.java.sun.com/thread.jspa?threadID=5208858&messageID=9840042#9840042
Uploading Files Using Servlet:
http://muimi.com/j/jakarta/commons/fileupload/
Case 2
The second method would more or less the same but here we would save the uploaded file
content is saved in the Database as a Blob and we would retrive it back using a dedicated image servlet again.
However,in terms of performance the second case implementation is very costly.
Try to refer below posts to get a better understading on the second case.
http://forum.java.sun.com/thread.jspa?threadID=5193481&tstart=50
http://forum.java.sun.com/thread.jspa?threadID=5211649&messageID=9853670#9853670
Hope this might help :)
REGARDS,
RaHuL

Similar Messages

  • Best way to manage images in a swing app

    Hi.
    I have a swing app that uses alot of images around 100+ at around 40kb each.
    I am currently using new ImageIcon("icon\\main.png")) to create them.
    Is this the most efficient way to manage images?
    Would it be more efficeint to store then in the mysql database?
    and / or use SwingWorker (http://java.sun.com/javase/6/docs/api/javax/swing/SwingWorker.html)
    Cheers
    Bobby

    Hi Bobby,
    It depends on what you want to be more efficient:
    1) CPU cycles
    2) Reducing jar size
    3) Ease of maintenance
    4) Prevent typing errors in file names
    For me, number 3 and 4 are important. So, what I generally do, is create an enum that desribes the images that are contained in the same package as the enum. Now I'm able to change the package name with no consequence. I only have to type the filename once and know when I have to double check of what I type. Something like this:
    package org.pbjar.geom.images;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.ImageIcon;
    public enum Images {
        AUTHOR_SMALL("TheAuthor.jpg"),
        AUTHOR_LARGE("PietKopLarge.jpg"),
        private final String filename;
        Images(String filename) {
         this.filename = filename;
        public ImageIcon getIcon() {
         return new ImageIcon(getImage());
        public BufferedImage getImage(){
         try {
             return ImageIO.read(getURL());
         } catch (IOException e) {
             throw new RuntimeException(e);
        public URL getURL() {
         return this.getClass().getResource(filename);
    }Piet

  • Best way to save images streamed from web to device?

    We have an app for browsing a catalog that streams content from a web server. There is an image for each product, some in JPG format and some in PNG format. Our server is fast and reliable so everything has been running smoothly so far, but we'd like to give users the option of saving the data to their device so they don't have to stream every time. I've only worked with SharedObjects before, which are capped at 100kb and won't be useful in this situation.
    What would be the best approach for storing the images, and keeping them from being overwritten during updates? Saving an uncompressed Bitmap will use too much storage space. Adobe's JPEGEncoder class is completely useless as it takes 10-30 seconds to save a moderately-sized image on a typical device. It also doesn't make sense to re-encode the JPGs, and we need to preserve the transparency in the PNGs.
    Right now we're using a Loader to retrieve the images and using loader.content to access the image data in code. Is it possible to save the image file in its original format locally when it is downloaded with a Loader? We would want the images stored in the application data and not accessible through the gallery. As for saving the data for each product (e.g. price, description, etc), would the built-in SQLite support be sufficient or should we create our own files?
    Thanks for any tips!

    We typically use a native extension to do this, but it is certainly possible in ActionScript.
    When the file has been downloaded, we save it to the applicationStorageDirectory.
    Next time, we check to see if exists locally, if so - use that and don't download.
       var file:String = renameFile(_externalHttpImage);
       //see if we already have a copy of the image
       var loader:Loader = new Loader();
       var ba:ByteArray = new ByteArray();
       if( fileExists(file)){
        file = File.applicationStorageDirectory.resolvePath(file).nativePath;
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, local_loader_complete);
        loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorOnChargeFile);
        var f:File = File.applicationStorageDirectory.resolvePath(file);
        if( f.exists){
         var fs:FileStream;
         try {
          //now load the size of the file
          fs = new FileStream();
          fs.open(f, FileMode.READ);
          fs.readBytes(ba);
          //  trace("READ " + fs.readUTF());
          fs.close();
         catch(e:Error){
          trace( "Error Loading Image File  '" +file + ": " +  e.message+ "\n"+ e.getStackTrace());
        loader.loadBytes(ba);

  • The best way to manage vi locations and dependencies?

    Hi,
    when i am updating my own vi version by creating a new folder with my files, somehow labview isn't so smart to link the subvi's and dll's that are also moved with the main programs.  now i am using project manager and the situation is even worse.  i am wondering if there is a best way of managing file dependency tree, for example, relative paths?
    also, it seems that labview treat llb files as folders, so packing (sub)vis that are refering each other in one llb doesn't solve the problem, ie the vi in the new copy of llb file will still refer to the old file even the new version is right next to it in the same llb file.
    if i archive the old files, labview becomes confused and fails to locate the new files.
    as my project grows bigger, i will have to spend lot of time relinking subvis.  really need to solve this problem.....
    - yi

    I don't see how you get this.
    But some pointers:
    Make sure all VIs are under one folder.
    Make sure all other versions of the files are not searchable (remove a backup-folder from your LabVIEW search paths)
    Create a LVproject.
    Add the main VI to the project.
    Open the main VI from the project
    If you get warnings, go over them one by one and select the VI you want to keep.
    Switch over to files view (available in 8.5 ctrl-e) and see if the VIs are in the expected locations, if not, open them (from the project), File-> save as (update callers)
    This will get your project cleaned up.
    From now on you only use the project window.
    To make a backup-file, create a source-distribution, where you will rename each file (a feature available in 8.5)
    If you  don't rename the files make sure you always close the project and any of it's files before opening a VI from the backup folder.
    Ton
    Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
    Nederlandse LabVIEW user groep www.lvug.nl
    My LabVIEW Ideas
    LabVIEW, programming like it should be!

  • Best Way to Host Front Panel in Web Browser

    Hello  All 
               I am almost confused with all methodology that Labview have to host the Top Level front panel in Web browser. My requirement is to  Monitor and control the Front Panel from remote location using web browser, but without installing any LV Runtime engine in Client machine. Also I want to stream the Videos in same or different page. Which is the best way to do this?. Web-service or CGI 
    Thanks & Regards
    Rigilkumar 

    Rigilkumar,
    If you don't want to install the LV runtime engine, that rules out the remote front panels.  However, you should still be able to build a web service to do what you want. This will be a bit more tedious because you'll have to build a thin client to have an interface with the web service. You can find an example of a thin client built in Adobe Flex here.
    If you're looking at streaming video as well, I recommend you look over Streaming IMAQ Images Over a Network (or Internet)
    Hope this helps,
    Misha

  • Best way to store image? will be a lot of image files

    I am working on a new project which involve user upload image to server and then do searching and view image. there will be a lot of image files. image will be displayed in web page as thumbnails, so there may be resized pic stored in server or resize on the fly.
    What is the best way to store image like this? as files in file system? database? etc...?
    Thank you very much

    Hi,
    When you are asking about the "best method for BDB", you should first read this: http://www.oracle.com/technology/documentation/berkeley-db/db/ref/am_conf/select.html
    When you know exactly what are the differences between the BDB access methods, then you will be able to figure out which is the best method for your requirements or to ask a more specific question.
    Regarding the second problem, you should read about isolation and degrees of isolation: http://www.oracle.com/technology/documentation/berkeley-db/db/ref/transapp/inc.html
    Regards,
    Bogdan Coman

  • Whats the best way to manage 100s of thumbnails?

    I'm trying to build a simple photo management app in java, like Picasa2. I want to be able to scroll through 100s of thumbnails. Whats the best way to manage them from a memory standpoint?
    a) can I load up 100s of thumbnails into a JScrollPane? If so, will it do anything special to manage memory for the thumbnails that are offscreen?
    b) should I just draw up a grid of JLabels and page through them like you would in html?
    Is there another approach? Is there any special way to manage the thumbnails that are offscreen (besides loading them all in memory ) and still get a fast response time?
    BTW, if anyone wants to join me in this project, I'm happy to opensource and share.

    Because for some of us, it takes a lot longer than 5 mins. Besides, I was on someone else's computer.
    Regardless, I've implemented JList for images, and it works really well. For those of you who are following in my footsteps, the answer is:
    JList renders ImageIcons by default.
    If you want to render a JLabel with an ImageIcon set to an image, you need to write a custom ListCellRenderer, but it turns out that is not too hard. But here is a follow-up problem:
    My app has JLabels that subscribe to an ImageLoader that loads images in the background. On init() the JLabel just has the ImageIcon set to a placeholder image:
              myJLabel.imgIcon = new ImageIcon();
              myJLabel.imgIcon.setImage( myPlaceholderImage );
    However, once the actual image is loaded, I call a refresh method to set the ImageIcon to a new image:
              myJLabel.imgIcon.setImage( myLoadedBufferedImage );
    My problem is getting the JList to render the updated JLabel. Right now, I keep a reference to the JList with myJLabel and call revalidate() on refresh, but that doesn't seem very clean.
    Is there an easy/natural place to get the JList to revalidate()?
    Can I easily know which JLabels are in the viewport of the JList scrollpane? That way I could revalidate only the visible JLabels or when scrolling.

  • What is the best way to manage multiple devices with one iMac - different users with seperate itunes accounts or one mac user with different itune logons and libraries?

    Hello
    I have just purchased an imac which I am very happy with.  In our household we also have two iphones (one mine and one husbands) and one ipod (my sons). We all have individual itunes accounts set up on our previous computer (not a mac). We have sepereate apps and music, although there may be the odd occasion where we would like to share a song (if this is possible) across devices.
    I am just wondering the best way to manage these devices using the new imac.  Should I create individual accounts to logon to the imac, then from within these launch our own itunes accounts and sync our devices with these.  Or should I be using one version of itunes, logging on to this with our different itunes usernames and storing things in libraries.
    Any help would be greatly appreciated. 
    Thanks

    I am presuming that we cannot share downloaded apps and music between accounts because of the copyright issue,
    Though I'm no copyright lawyer, as long as it's within a household, you can share content among users. Such sharing is, absent specific language preventing it not present in the iTunes Store terms of use, generally considered to be "personal use". So you can share apps and music amongst your users on your computer and with their devices. You just can't give any of that content to friends or relatives who don't live with you.
    What I am not clear on, it making sure that this appears in each itunes account - is it easy to find the file storage folders that match the itunes accounts and what would these be?
    The iTunes library and files are by default in a user's Home/Music folder. But you don't have to find the folder; in fact putting a file into the folder yourself won't add the file to iTunes. Just drag the file into the iTunes window. iTunes will copy it to the correct location.
    Regards.

  • What's the best way to manage Apple IDs for multiple devices?

    Hi,
    We have
    a shared Macbook air
    a shared iPad
    my iPhone
    his iPhone
    We want to put one ID on the Macbook and iPad that we can use to have the same iMessage on both and that we can put a card on and use in the iTunes store etc.
    We also want to have our own iMessages on our iPhones, plus be able to use the account with the cards on them to purchase and share across devices...
    What's the best way to manage them all?

    Welcome to the Apple Community.
    iTunes is straight forward, just use the same ID on all of them.
    What exactly do you want to see in messages on the Mac and iPad, messages combined from each of your phones or a different account just for both of you.
    You should think about what you want in calendars, contacts etc, on your shared devices.

  • Best way to manage multiple iTunes accounts (from different countries)

    Ok, wasn't sure if this was the best community to ask this question, but here goes.
    My wife and I have two iTunes accounts, one originally from the United States, the other originally from Australia. Over the years content has been purchased using both accounts.
    We currently reside in Australia and primarily view our content on Apple TV. So far we’ve had no problems logging into either account and accessing all our content.
    Now, I have a fear (perhaps an irrational one) that if we choose to permanently reside in one country (Australia, the US, somewhere else) that at some point Apple may cancel/restrict one of these accounts. Since there is no way for me to merge all our purchased digital content into the one digital library, we’re now wondering the best way to manage this?
    I see there is a new "family sharing" feature soon to be launched, so that may be half the solution (assuming it will work with family members in different continents). If so, the other half of the question is, will we be able to still purchase content on both accounts? While in Australia since April we have rented movies on both accounts, but have only purchased movies etc on the Australian account (we can still do this on the US account, but we haven't risked it in case it gets cancelled because Apple decides we're no longer in the US - in other words, we don't want to spend $$$ on movies we may not be able to access in future).
    What do others think? What is the best way for us to manage our scenario? Or am I worried about nothing and we can continue purchasing content on either account without fear of “losing” it later?
    Any advice would be greatly appreciated! I did try and ring Apple, but the guy refused to give me advice until I provided my details and I did't want to do that at this stage.
    Thanks everyone for your help!
    MM

    You may lose the ability to purchase content from the USA, but any content you've already bought will remain accessible. Back everything up.
    (112502)

  • How is the best way to manage the stats table?

    Hello!
    I have the Integration 2.1 working with an Oracle 8.1.7 db. I noticed that the table
    STATS is growing pretty fast.
    How is the best way to manage this table?... I haven't found something related with
    this issue in the documentation, but at least I want to know how to safely delete
    records from this table.
    For example, if I know the minimal time I have to keep in the table, is quite simple
    to create a shell script and/or Oracle pl/sql job to trim the table.
    I hope somebody can help me!!!!
    Thank you!
    Ulises Sandoval

    Write an app people want to buy and rate highly.

  • What is the best way to manage photos - Dropbox (with sync), Facebook (with sync), iPhoto, etc.?

    With so many cloud based and wireless syncing services, I'm lost as to the simplest way to keep photos sync'd as well as backed up. My dropbox is currently syncing all photos I take with my iphone, but in an overall folder called CAMERA UPLOADS, so they are uncategorized. I upload pics to facebook, which facebook also has a sync photos feature, but I don't necessarily want all photos uploaded to facebook. What has worked best for everyone so that there aren't a ton of dupicate photos everywhere, and multiple syncs of the same photos?
    Also, what is the best way to manage my iPhone photos generally? I'm never sure if I delete a photo from my phone, does it delete it on my computer via iCloud? Sometimes I just take a picture to send to a friend that I don't need to keep, while others are ones I want to sync to my computer. Can I control when deleting that it be deleted everywhere or just on the device? And alternately, can I choose certain photos not to sync via iCloud?
    iCloud makes me nervous. Once when I wanted to place all photos of my pup into a folder, I selected the photos on my iPhone and accidentally clicked delete instead of move. No big deal, I figured they'd be at home sync'd on the cloud. But since I'd deleted them on my phone, the cloud deleted them on my home computer too and the photos were lost.

    I am presuming that we cannot share downloaded apps and music between accounts because of the copyright issue,
    Though I'm no copyright lawyer, as long as it's within a household, you can share content among users. Such sharing is, absent specific language preventing it not present in the iTunes Store terms of use, generally considered to be "personal use". So you can share apps and music amongst your users on your computer and with their devices. You just can't give any of that content to friends or relatives who don't live with you.
    What I am not clear on, it making sure that this appears in each itunes account - is it easy to find the file storage folders that match the itunes accounts and what would these be?
    The iTunes library and files are by default in a user's Home/Music folder. But you don't have to find the folder; in fact putting a file into the folder yourself won't add the file to iTunes. Just drag the file into the iTunes window. iTunes will copy it to the correct location.
    Regards.

  • What is the best way to manage my iPhoto, which is taking up too much space on my MacBook Pro?

    What is the best way to manage my iPhoto, which is taking up too much space on my MacBook Pro?
    Specifically, I'd like to keep some of my favorite pictures on the laptop while moving the rest to an external hard drive. Is there a way to tag just a few pictures inside an event/album as "favorite", while storing the rest in an EHD, but still keep them connected to the same event/album? I'd like to have just the favorite pictures on the laptop, but when I have the EHD connected,  be able to view all my pictures in the same place, and not have to browse through separate hard drives. Ideally, whether or not a picture is designated as "favorite" will determine where it resides.
    Is this at all possible?
    I have only 7 GB left on my HD and I'm desperately needing a solution!
    Thanks!

    You need two libraries to do this. One on the external with all your Photos. One on the internal with a subset - your favourites. You do it this way to make backing up easier - that is, back up the library with everything, so you're only backing up one.
    Make sure the drive is formatted Mac OS Extended (Journaled)
    1. Quit iPhoto
    2. Copy the iPhoto Library from your Pictures Folder to the External Disk.
    Now you have two full versions of the Library.
    3. On the Internal library, trash the Events/albums/photos you don't want there
    Now you have a full copy of the Library on the External and a smaller subset on the Internal
    Some Notes:
    As a general rule: when deleting photos do them in batches of about 100 at a time. iPhoto can baulk at trashing large numbers at one go.
    You can choose which Library to open: Hold down the option (or alt) key key and launch iPhoto. From the resulting menu select 'Choose Library'
    You can keep the Library on the external updated with new imports using iPhoto Library Manager

  • Best way to manage iMac and two iPads?

    Have a new iMac (Intel,OS X Lion) and two iPad 2.  The iMac is mine the and iPads are my kids. We all have our own apple IDs.  I ultimately want to do any downloading/purchasing on the iMac and then transfer the music/apps/movies to the iPads.
    What is the best way to manage them so I can sync the iMac to the iPads? 
    Can I download apps/music etc. on my iMac and then sync it to both of the iPads?
    Do I need to use the same Apple ID on all of them if I want to sync the iMac to the iPads?   I would prefer not to store credit card info on the kids iPads.
    Whats the most efficient way to handle this?  Sorry for so many questions.  Its a hazard of being a newbie.
    Thanks, Courtney

    The best way I can think of is for each iMac user create their own account for them. Then when they log in they can sync to their own AppleID account. It keeps things simple and separate. If you don't know how to create accounts please look over http://docs.info.apple.com/article.html?path=Mac/10.7/en/mtusr001.html

  • Best way to manage large library with AAC and MP3 versions of files

    I have a large library of music. I listen to music through iTunes and iPod/iPhones, but also other devices which only support MP3, and not AAC. I typically convert iTunes purchases to MP3, but I'm left with two copies of each song in the same folder. I'm looking for recommendations on the best way to manage what would essentially be a duplicated music library - a high quality version I use with my iTunes/ipods, and a lower quality MP3 version for the devices that only support that format.

    I have had a similar problem. I have all my music residing on a NAS where I access it from iTunes (for managing my iPods/iPhones) and a Tivo PVR (which is connected to my house stereo system.) The problem is that Tivo does not recognize AAC. So I've used iTunes to create mp3 versions of all my purchased AAC music. Because the NAS is set as my iTunes media folder location, iTunes puts the mp3 copies back into the existing folder structure (which it keeps organised) on the NAS. Tivo accesses the NAS directly, over the network. But iTunes also puts the additional copy into the iTunes library which leaves me with multiple copies of the same songs on iTunes AND my iPods. Having multiple copies on the NAS (mp3 for Tivo and AAC for iPod) is OK: I've got plenty of space on the NAS and the Tivo doesn't 'see' the AAC files.
    The solution I'm planning to implement is to delete the mp3 entries from the library as soon as I create them (leaving the files in the media folder.) But what I'm looking is for a way to automatically select the mp3 copies (for deletion) from the existing duplicates list. Any ideas?

Maybe you are looking for

  • Portal 7.3 masthead customization - How to remove Logoff dialog box "Are you sure you want to logoff?"

    Portal 7.3 masthead customization - How to remove Logoff dialog box "Are you sure you want to logoff?" I have recently upgraded our portal to 7.3 sps10 and we are using the Ajax framework I have a requirement to Remove the Logoff Dialog box "Are you

  • Pics turn red when ken burns is turned on

    hi i was just editing a slideshow im making and when i added the ken burns effect all my photos turned red and stayed that way i was wondering how to get rid of this

  • Inheriting the values in tree structure

    In the below graph if P1 value is 10 then all node value should be 10. But at any level of node we can change the value of node for example If I override P6 with value 20 then p6, p7, p8 values should be 20 and remainings with 10 P1 10 P2 P3 10 30 P4

  • Report from Dataset won't display on Production Machine

    I have a report that was developed from a dataset. It displays perfectly on my development machine, but produces a 'Database Login Error' , Error: Object reference not set to an instance of an object. when I try to access it from my production server

  • IManAcrobatReader.api with Reader 11

    IManAcrobatReader.api doen't allow integration with Imanage using reader 11, is there a new api plug in to work with the new version? I have the plug in that works fine with version 10 in C:\Program Files\Adobe\Reader 11.0\Reader\plug_ins\Interwoven