How to display images and information

how to display images and information(e.g. like questions) on a jsp page that stored in a database

Look As far as i can see....
Utlimately every file could be expressed as a bytes buffer.
so say if you have a bean called Choice Bean which is expressed as
public class ChoiceBean{
   private String choiceid;
   private String choicedesc;
   private byte image[];
   public void setChoiceId(String choiceid){
          this.choiceid = choiceid;
    public String getChoiceId(){
           return this.choiceid;
      public void setChoiceDesc(String choicedesc){
           this.choicedesc = choicedesc;
       public String getChoiceDesc(){
           return this.choicedesc;
       public void setImage(byte image[]){
              this.image = image;
         public byte[] getImage(){
              return this.image;
}QuestionList.java:
===============
public class QuestionList{
     private List<ChoiceBean> choicelist;
      /*Other member variable declarations*/
       public  List<ChoiceBean> getChoiceList(){
                /*Custom code where you may build the list by querying the DA layer*/
                 return this.choicelist;
     public int search(String choiceid){
             int index = -1;
             for(int i =0 ; i < this.choicelist.size() ; i++){
                    ChoiceBean cb = this.choicelist.get(i);
                     if(cb.getChoiceId().equals(choiceid)){
                            index = i;
                            break;
             return index;
    /* Other member method declarations */
}and you are retreving List<ChoiceBean> from DB using your query & have created a session attribute / <jsp:useBean> named ChoiceList
NOTE: sometimes your application server can go out of bounds as you are consuming a lot of memory by creating an arraylist object.
use the following methodology to display images & choices
sample.jsp:
=========
<jsp:useBean id="QuestionList"  class="com.qpa.dao.QuestionList" scope="session"/>
<TABLE>
<%
/* QuestionList.getChoiceList() is a method which fetches data from the DB & returns it in form of  List<ChoiceBean> */
List<ChoiceBean> choicelist = QuestionList.getChoiceList();
for(int i =0 ; i < choicelist.size() ; i++){
%>
<TR>
<TD><%!=choicelist.get(i).getChoiceId()%></TD>
<!-- calling servlet which renders an images in JPG format based upon given choiceid(unique field) -->
<TD><IMAGE src="ImageServlet?choiceid=<%!=choicelist.get(i).getChoiceId()%>"/> </TD>
<TD><%!=choicelist.get(i).getChoiceDesc()%></TD>
</TR>
<%
%>
</TABLE>
<%
    session.remove("QuestionList");
%>
NOTE: usage of JSTL or any other custom built tag-libraries makes life more simpler in the following case
ImageServlet.java:
===============
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        byte buffer[] = null;
        HttpSession session = request.getSession(false);
        /*getting the QuestionList from the session*/
        QuestionList ql = null;
        String choiceid = new String("");
        try{
             choiceid = request.getParameter("choiceid");
             /*getting the QuestionList from the session*/
            ql = (QuestionList)  session.getAttribute("QuestionList");
        } catch(Exception exp){
        if(choiceid.equals("") == false &&  ql != null ){
            List<ChoiceBean> clist = QuestionList.getChoiceList();           
               assuming that you have created a serach method which searches the entire choice list and would give you
               the index of that object which is being refered by unique choiceid and returns -1 if not found
            int index =  QuestionList.search(choiceid);
            if(index != -1){
               ChoiceBean cb = clist.get(index);
               buffer = cb.getImage();
        if(buffer != null){
             // assuming that we have stored images in JPEG format only
             JPEGImageDecoder decoder = JPEGCodec.createJPEGDecoder(new ByteArrayInputStream(buffer));
             BufferedImage image =decoder.decodeAsBufferedImage();
             response.setContentType("image/jpeg");
             // Send back image
             ServletOutputStream sos = response.getOutputStream();
             JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sos);
             encoder.encode(image);
        } else {
           response.setContentType("text/html");
           response.getWriter().println("<b>Image data not found</b>");              
}However,i still feel there are few loopholes with this approach where Application Server can eat up a lot of heap space which may result in outofmemorybound exception.
Hope this might help :)
REGARDS,
RaHuL

Similar Messages

  • How to display image and data in module pool screen?

    Hi,
    I want to display image and relevant data besides the image in module pool screen, I am using docking container to display the image.
    Actually I am able to display image or data any one but not both.
    one more thing I want to display multiple images and their data.
    Please suggest some one if you have any idea.
    Regards,
    Dileep.

    You can try below way, I have used in report.
    DATA: gc_docking              TYPE REF TO cl_gui_docking_container, "#EC NEEDED  "Docking Container
           gc_split                 TYPE REF TO cl_gui_easy_splitter_container, "#EC NEEDED  "Splitter
           gc_top_container         TYPE REF TO cl_gui_container, "#EC NEEDED  "Top Container
           gc_bottom_container      TYPE REF TO cl_gui_container, "#EC NEEDED  "Bottom Container
          gc_document              TYPE REF TO cl_dd_document, "#EC NEEDED  "Document
           gc_events                TYPE REF TO lcl_event_class, "#EC NEEDED  " Local Event Class
           gc_grid                  TYPE REF TO cl_gui_alv_grid, "#EC NEEDED  " ALV Class
    " Creating Docking
    CREATE OBJECT gc_docking
           EXPORTING
             ratio = c_95.
         IF sy-subrc EQ 0.
    * Splitting the Docking container
           CREATE OBJECT gc_split
             EXPORTING
               parent        = gc_docking
               sash_position = c_10 "Position of Splitter Bar (in Percent)
               with_border   = c_1. "With Border = 1 Without Border = 0
         ENDIF.
    *   Placing the containers in the splitter
         gc_top_container = gc_split->top_left_container .
         gc_bottom_container = gc_split->bottom_right_container .
    *   Creating Grid
         CREATE OBJECT gc_grid
           EXPORTING
             i_parent = gc_bottom_container.
       ELSE.
    * Background job handling
         CREATE OBJECT gc_grid
           EXPORTING
             i_parent = gc_docking.
       ENDIF.
    *   Creating the document
       CREATE OBJECT gc_document
         EXPORTING
           style = 'ALV_GRID'.
    Regards,
    Sameer

  • How to display List and Image on Single Screen?

    Hi Friends,
    I wanna display Image and List on single screen.
    Its not possible using Form which will contain both. either I can list or form which contain image as far I know.
    I have seen one J2ME application which contain Image and below that there is list. Can anybody tell me how?
    Thanks,
    Rohan Chandane

    Hi,
    Are you able to put a list and image into a form.
    If so plz let me know the method to do tht.
    thanks.

  • How to display images on my internal isight?

    Hi,
    I just bought the new iMac 2 gig dual. Running on 10.5.2.
    I wanted to know how to display images on my screen during a video conference chat without resorting to holding up a print out to the camera? I need something where I can switch from video mode to image mode and show a single image at a time if I need to. All that while still talking of coarse. If it isn't possible with my iSight software, can you point me to other software I can download and still use my built in cam?
    I hope I was clear enough in asking this.
    Thanks
    Liban

    Welcome to Apple Discussions, Liban
    iChat can do what you want, but I do not know of any web-based video chat site that can.
    Look for Help or Support information on the site you are using or ask the Webmaster if his site has the capability to do what you want.
    EZ Jim
    PowerBook 1.67 GHz w/Mac OS X (10.4.11) G5 DP 1.8 w/Mac OS X (10.5.2)  External iSight

  • How to display date and time on jsf page

    Hi,
    how to display date and time on jsf page
    we are using 11.2.0.0 jdeveloper on windows.
    thanks
    Edited by: user12187801 on 26-Jul-2012 01:42

    Your question is certainly lacking some information.
    If you want a constantly updating date/time - then JavaScript is your best bet, and Google would find you examples like [url http://www.webestools.com/scripts_tutorials-code-source-7-display-date-and-time-in-javascript-real-time-clock-javascript-date-time.html]this
    If you meant something else, then it's back to you to explain.

  • Hi Everyone,  I am using iPhone5, my question in how to display name and contact number both stored for incoming and outgoing calls? If I have saved five different numbers with a same name, how do I recognise that from which number caller is calling?

    Hi Everyone,  I am using iPhone5, my question in how to display name and contact number both stored for incoming and outgoing calls? If I have saved five different numbers with a same name, how do I recognise that from which number caller is calling?

    I have friends all over Europe, does it matter what number they use to call me? Nope! All incoming calls are free for me.
    The only time you ever have to worry about which number is if you get charged for incoming domestic/international calls.
    You can tag their number (work/home/iphone) and that may show on the CallerID accordingly.
    It should show, John Doe
    underneath,    work/home/mobile
    For example:
    http://shawnblanc.net/images/img-0009-1.png

  • How to display image?

    Hi all,
    How to display image from the database table in the adobe form by using web dynpro abap?
    I want to display image in the adobe interactive form by using web dynpro abap.
    Please help me.
    Regards,
    srini

    Hi Srini,
    If you go through the article you might have seen the following piece of code
    *** Send the values back to the node
      lo_el_z_if_test_cv->set_static_attributes(
        EXPORTING
          static_attributes = ls_z_if_test_cv ).
    " here ls_z_if_test_cv has the image in XSTRING format which has beeen retrived using METHOD get_bds_graphic_as_bmp of CLASS cl_ssf_xsf_utilities
    " In  your case you need to just use the select query n fetch it from your table; ( provided your image is store in XSTRING format )
    How is your image stored in your database table ?
    Regards,
    Radhika.

  • How to use image and text in same component

    Hello
    Do you know how to use image and text in same component in java ?
    because i need this in my project ,which is chat application , to
    put the received text and any image if it is need within the text

    thanks levi_h
    JTextPane class extends JEditPane and allows you to embed
    images or other components within the text managed by the component

  • How to read bytes(image) from a server ?how to display image after read byt

    How to read bytes(image) from a server ?how to display image after reading bytes?
    i have tried coding tis , but i couldnt get the image to be display:
    BufferedInputStream in1=new BufferedInputStream(kkSocket.getInputStream());
    int length1;
    byte [] data=new byte[1048576];
    if((length1=in1.read(data))!=-1){
    System.out.println("???");
    }System.out.println("length "+length1);
    Integer inter=new Integer(length1);
    byte d=inter.byteValue();

    didn't I tell you about using javax.imageio.ImageIO.read(InputStream) in another thread?

  • How to display Lines and Boxes in SAP Script

    hi,
    Can any one help me how to display Lines and Boxes in SAP Script.
    Regards
    kiran

    The SAP printer drivers based on page-oriented printers use these commands when creating output whereas the line printers and non-supported page-oriented printers ignore these commands.
    Syntax:/: BOX [XPOS] [YPOS] [WIDTH] [HEIGHT] [FRAME] [INTENSITY]
    This command draws a box of the specified size at the specified position.
    The following calculation is performed internally to determine the absolute output position of a box on the page:
    X(abs) = XORIGIN + XPOS
    Y(abs) = YORIGIN + YPOS
    WIDTH determines the width of the box.
    Default: WIDTH value of the SIZE command.
    HEIGHT determines height of the box.
    Default: HEIGHT value of the SIZE command.
    FRAME determines the thickness of frame.
    Default: 0 (no frame).
    INTENSITY determines the box contents as a grayscale percentage.
    Default: 100 (full black)
    The other details I guess is provided by friends who have posted before me.
    Regards,
    K.Sibi

  • How to display images in TextArea? and how to make some of the text clickab

    1) How do i make TextArea display images?
    (example a client program, where people chat, put :) and get a smily image)
    2) For example if text is http://www.something.com in textArea, a person can click it, and my custom dialog will apear saying something about this link.......

    This has been discussed very many times! It is solvable. Search the forum!
    one way is to make a custom textarea extending Canvas, and painting the text in the paint() method. You need a paint method with drawString and drawImage calles to make it the way you describe it. You also need to add a MouseListener for detection of clicking.

  • How to Display IMAGE BLOB stored in a table in a html region APEX

    Need to know how to display an image stored in a table in a HTML APEX Region.
    Please

    Hi
    Please explain what you mean by it doesn't work?
    Are there errors messages, at what point, how far did you get and exactly what did you do????
    Please provide more information.
    Thanks
    Ben

  • How to display image on Portlet ?

    Dear all,
    I am now designing an application using Oracle Portal to maintain a company's employee records.
    The application allows HR personnels to input employee information such as name, gender, age and so on. In additional, a photo of 250x300 will be uploaded to database as well.
    The application allows hr personnels to query the database for employees and the photos will be displayed on web.
    I will use JDeveloper for the development. I want to know how to display the photos on the web in Portlet?
    thanks
    George (HK)

    Well at the end of the line its still plain old html that is used to display images, to display an image in html (correct me if im wrong) the image has to be in the webfolder (or it can be a servlet that generates an image)
    You are getting the image from a database, so you need a servlet that gets this image and converts it to a format the html tag < img src="..." > understands.
    To be honest I never done this, but Im curious how you will do it.
    You could also try to use AJAX and load the image dynamically, you'll still need a servlet though. You must also understand that a portlet differs a little bit from a servlet, portlet need a portal to run, servlet can run on its own.
    Hope this helps, I hope you also get some other answers, let me know if you succeed, im curious

  • How to transfer images and music from PC (Windows 7) to iPhone?

    Hello:
    Could someone please inform me how can I transfer images and music from a PC (Windows 7) to my iPhone (3GS)?

    Hi, RichardParker,
    I have also meet problems to transfer music from PC to iPhone, and I had solved it now. You can do the following steps,
    1. Copy music to your phone memory
    2. Exported contacts to SD Card (on Android phone) in VCard format
    3. Transfered VCard file from SD Card to PC
    4. Created a Google Account
    5. Opened the Google Account from a browser (on PC), go to Contacts, and then uploaded VCard contacts to the Google account
    6. Configured the iPhone (using a separate Windows user account - so as to allow for importing pictures & videos through iTunes)
    7. Created a "CardDAV" account on the iPhone and synchronised all Contacts
    If you have any question ,you can ask me about iPhone Transfer. And I hope the steps above works.

  • How to show image and file field

    Hi,
    I try to bind DataTable with Sales-Rep_Data_tbl under Order database source (within Creator).
    The columns have IMAGE and RESUME.
    After binding and run, the two fields show no meaning in browser. Should I do some extra work? How do I display them?Thanks!

    Hi, Runak/Creator Team:
    Thanks a lot for quick response!
    I followed the steps there, but after run, the image still couldn't be displayed . It 's just a "X" icon there.
    I don't know the reason.
    If "Sample Application" in tutorial offers similar application to download, it would be wonderful.

Maybe you are looking for

  • Nokia E5 email update and now can't read email

    Hi, I downloaded the nokia email 3.21 update last night, and turned the phone off and on again as per instructions but now I can't read my emails (hotmail account)  as they just come up a load of jumbled letters and symbols, anyone know how to fix th

  • Sending Mail to Outlook

    Hi All, Through Report RSWUWFML2 i am sending workitems to Outlook, But the mails are going in Junk Folder. System is ECC 5.0 Please suggest what needs to be done. Thanks and Regards, Vaibhav

  • How to populate DUNS_NUMBER in AR through Customer Interface tables

    Hi, We are working on Customer Interface using custome Interface tables and run the standard Customer Interface program. As part of source data, we have data for D-U-N-S number, which should be populated to D-U-N-S number field displayed under Profil

  • Why can't I download OS X Server (Spinning wheel)?

    Morning Gurus, So I've bought a mac-mini to set up as my companies new server, I'm about to set it up for partitioning so that I have a mirrored drive etc. But, unrelated I'm trying to purchase the OS X Server app from the app store, yet all I'm gett

  • Getting a broken iPhone replaced?

    Hey, I recently smashed the front and back of my iPhone 4s and I've just been to the apple store and they've informed me that it needs to be replaced for 220, I am just wondering if its possible to pay extra and get it replaced with a newer version?