How to display uploaded jpeg in jsp

hi all,
i am uploading image(jpeg) using FormFile in ..............
then i am trying to display into the jsp but its display bytes only...........
my code is as below
jsp
<html:form action="/viewImage.do" method="post"     enctype="multipart/form-data">
     <table cellpadding="0" cellspacing="0" border="0" summary="Image table">
          <tr>
               <td align="right">Image </td>
               <td align="left">
                    <html:file property="image" />
               </td>
          </tr>
          <tr>
               <td align="center" colspan="2">
                    <html:submit property="saveImage">Upload Image</html:submit>
               </td>
          </tr>
</table>
</html:form>
------------------------my action is
public void disImage(ActionMapping mapping,
               ActionForm form, HttpServletRequest request,
               HttpServletResponse response) throws Exception {
          CompanyImageForm companyImageForm = (CompanyImageForm)form;
          FormFile myFile = companyImageForm.getImage();
     String contentType = myFile.getContentType();
     String fileName = myFile.getFileName();
     int fileSize = myFile.getFileSize();
     byte[] fileData = myFile.getFileData();
InputStream in = new ByteArrayInputStream(fileData);
     BufferedImage image=javax.imageio.ImageIO.read(in);
response.setContentType(contentType);
OutputStream sos = response.getOutputStream();
ImageIO.write(image,"jpeg",sos);
}

Well here is an idea for you...
1).Upload a File.Now this would be associated with an object like FileItem or FormFile whatsoever implementation we are using make sure the View Object we are using for this implementation is Serializable.
2).Save the View Object (Form Bean) under the scope of session and forward/redirect it to a JSP.
3).In the redirected/fprward JSP use <img> tag or equivalent framework tag and make sure you refer the src to a dedicated ImageServlet / Backing Bean(FormAction) Action or etc as per URL settings you are using.
4).Use the logic which my fellow poster Balus has asked you to apply.
Hope that might give you some idea.
REGARDS,
RaHuL

Similar Messages

  • How to display uploaded image in jsp page.

    Hello,
    I am using struts 1.2.9 and and have uploaded image on the server. Now what I want to do display the image in jsp page after clicking on one link in jsp. I have tried many thing to display image in jsp page. But I am getting an error during displaying image in jsp. I have displayed absolute path in servlet. and used InputStream and outputstream to display image in jsp page.
    Can any one help.
    Thanks in advance
    Manveer Singh

    Follow this. This topic is very popular recently on the forum.

  • Display uploaded file on JSP page

    Hi All,
    I want to display uploaded file in JSP.
    Initially I am displaying File Name after saving the file & click on edit link.
    i.e on JSP Page I have File Upload component & save button.With that save button I am saving my file to databse.
    So when I click on edit link I am getting that file name from Databse then I am displaying it.
    But now I want to display uploaded file name on JSP page before saving to databse.i.e I will have browse & Upload button.When I click on browse button I will open window from where I will select file.
    This is working fine as,<x:inputFileUpload id="uploadfile" value="#{errorLotBean.file}" storage="file"></x:inputFileUpload>
    But when I click on upload button that uploaded file should be displyed there only.Can anyone please tell me how to do this ?
    Thanks
    Sandip

    Thanks a lot Siefert,
    I tried the way mentioned in URL.
    But what if I want to display all uploaded file on my screen.
    i.e. If user click on browse & select File A then click on upload button.
    (Here the File A will be displayed) with code
    <h:outputtext value="#{benaName.file.name}"
    But what if after displaying File A if user decide to upload another file File B.
    How to display that ?
    with <h:outputtext value="#{benaName.file.name}" its dispalying one file only.
    Thanks
    Sandip

  • How to display a jpeg in corner of a frame or change default bg colour?

    I am having problems of a different sort regarding display of an image in a frame. I wish to display a jpeg in a frame such that it sits exactly in the top left corner. As it is, it always sits a few pixels left and down from the corner, leaving an annoying white border. The only way to get rid of the border is to create an individual html file for every image so that the bg colour can be set to match the rest of the page - but surely there is a way to either change the default bg colour in the users browser when viewing the site or to sit the image dead in the corner so that there is no need.
    It's driving me nuts!

    Hi Greystar69 ,
    Try the following code. this code helps to understand easily how to bring it.
    acknowledge me
    import java.awt.* ;
    import javax.swing.* ;
    public class FrameBg extends Frame {
         private Image img ;
         public FrameBg() {
              super( "Test" ) ;
              img = new ImageIcon( "D:/images/rose.png" ).getImage() ;
              if( img == null ) {
                   System.out.println( "Image is null" );
                   System.exit( 0 ) ;
              setLayout( new FlowLayout() ) ;
              add( new JButton( "How   is   it?" ) ) ;
              add( new Button( "Is   it    ok?" ) ) ;
              setSize( 400 , 300 ) ;
              setVisible( true ) ;
         public void drawBackground( Graphics g ) {
              int w = getWidth() ;
              int h = getHeight() ;
              int iw = img.getWidth( this ) ;
              int ih = img.getHeight( this ) ;
              for( int i = 0 ; i < w ; i+=iw ) {
                   for( int j = 0 ; j < h ; j+= ih ) {
                        g.drawImage( img , i , j , this ) ;
         public void paint( Graphics g ) {
              drawBackground( g ) ;
              super.paint( g ) ;
         public static void main(String[] args) {
              new FrameBg() ;
    }

  • How to display text file in JSP?

    Hi,
    I am new to servlet/JSP/java programming.
    I have been able to download a file using ftp. I dont know who to display it in JSP.
    Here is my code. Any help will be appreciated...
    <%@ page import="java.util.*" %>
    <%@ page import="java.lang.*" %>
    <%@ page import="java.net.*" %>
    <%@ page import="java.io.*" %>
    <%@ page import="com.dmhistory.*" %>
    <html>
    <head>
    <title>Untitled</title>
    </head>
    <body>
    <%
    byte[] bytes = new byte[4096];
    URL theUrl = new URL("ftp://user:passwd@host/migr/Movers_for_Ora8/BG/logs/FLD-PAC3-20020311.log");
    BufferedInputStream in = new BufferedInputStream(theUrl.openStream());
    BufferedOutputStream outstream = new BufferedOutputStream(new FileOutputStream( new File( "D:/temp/log.txt" )));
    int pos = in.read( bytes );
    while ( pos != -1) {
    outstream.write( bytes, 0, pos );
    pos = in.read( bytes );
    %>
    <%
    in.close();
    %>
    DONE!!!
    </body>
    </html>
    How can i display this downloaded file in the browser?
    I want to display it in the original format i.e which new line and carriage returns...line by line..
    Thanks,

    Hi,
    I finally go it to display. but now I have new problem. The browser shows the text without the /n/r.
    But when I view the source using 'view->source', if see that the text has got proper format with newline and carriage returns.
    Any ideas how to display it correctly in the browser?
    <%
                   URL theUrl = new URL("ftp://user:pwd@host/migr/Movers_for_Ora8/BG/logs/FLD-PAC3-20020311.log");
                   //URL theUrl = new URL("ftp://dbcmaint:[email protected]/migr/Movers_for_Ora8/SNP/logs/SNP-PAC2-20020314.log");
                   URLConnection uc = theUrl.openConnection();
                   InputStream content = uc.getInputStream();
                   BufferedInputStream in = new BufferedInputStream (content);
                   LineNumberReader lnr = new LineNumberReader (new InputStreamReader (in));
                   String tempStr = "";
                   String str = "";
                   while ((tempStr = lnr.readLine()) != null) {
                   str += (tempStr);
                        %>
                        <%=tempStr%>
                        <%tempStr = "";
                        %>
                   <%
                   in.close();
                   lnr.close();
              %>
    Thanks

  • How to display array values in jsp of screen flows

    Hi,
    can u please help me .
    I am having one array variable i have stored all the values but i have to display that in JSP page .how to display
    Edited by: user12171025 on Nov 4, 2009 11:11 PM

    Hi,
    I think that its necessaries to use AJaX.
    I am implemeting something like that.
    I have a input text that works like a filter and depends on what my user types in input text I populate my table with some information.
    In order to do that, I put in my JSP a div with an Id and I used ajax, like that:
    function ajaxFunction()
              var xmlhttp;
              if (window.XMLHttpRequest)
              xmlhttp=new XMLHttpRequest();
              else if (window.ActiveXObject)
              // code for IE6, IE5
              xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
              else
              alert("Your browser does not support XMLHTTP!");
              xmlhttp.onreadystatechange=function()
                                                      if( xmlhttp.readyState==4 )
                                                           document.getElementById("tabelaResponsaveis").innerHTML = xmlhttp.responseText;
         var resp = "<f:invokeUrl var='solicitacao' methodName='getResponsaveis'/>";
         xmlhttp.open("POST",resp,true);
         xmlhttp.send(null);
    getResponsaveis is a method inside my BPM that returns a HTML code (the table HTML code with all the information that I need to show.
    I Hope to help
    Thanks Marcos

  • How to display JCO.Table in jsp, CRM ISA

    Hi,
    I have got a JCO.Table with results from teh CRM system and now want to display this in ISA.
    Is there any templates, or code, that could guide me as to how to transfer the table to jsp.
    thanks,
    sunil

    Hi Sunil,
    The code from bean class is here,
    public void listDetails(String releaseGroup,String releaseCode)                                 
    throws Exception
                    try
                         if (mRepository == null )
                              System.out.println("NuLL");
                         try
    IFunctionTemplate                                         ft=mRepository.getFunctionTemplate("BAPI_REQUISITION_GETITEMSREL");
    myFunction=ft.getFunction();
                   catch (Exception ex)
                   throw new Exception(ex + "Problem retrieving JCO.Function object.");
          if (myFunction == null)
         System.exit(1);
    mConnection.execute(myFunction);
                   JCO.ParameterList input = myFunction.getImportParameterList();
                           input.setValue(releaseGroup,"REL_GROUP");
                           input.setValue(releaseCode,"REL_CODE");
                           input.setValue(releaseFlag,"ITEMS_FOR_RELEASE");
                             System.out.println("Imported");
                         catch (Exception ex)
                              ex.printStackTrace();
                              System.exit(1);
                          mConnection.execute(myFunction);
                JCO.Table codes = null;
               codes =myFunction.getTableParameterList().getTable("REQUISITION_ITEMS");
               size =codes.getNumRows();
               if (size == 0)
                  System.out.println("No value matches the selection cretaria");
               purchaseRequisitionNo = new String[size];
               item   = new String[size];
               requestorName = new String[size];
               description = new String[size];
               creatorName = new String[size];
               purchaseRequisitionDate = new String[size];
               plant = new String[size];
              // getter methods
         public int  getSize() { return size; }
         public String getPurchaseRequisitionNo(int i){return                                                        purchaseRequisitionNo<i>; }
          public String getItem(int i) { return item<i>; }
         public String getDescription(int i) { return description<i>; }
         public String getCreatorName(int i) { return creatorName<i>; }
         public String getPurchaseRequisitionDate(int i)
                                             {return purchaseRequisitionDate<i>; }
         public String  getplant(int i) { return plant<i>; }
    Now in the JSP page get the number of entries in the table and try to get row by row from the bean class using the row number.
    <%
    int count = PR.getSize() ; // This method will return the number of
    rows in the table.
    for ( int i = 0; i < count ; i++ ) {
    %>
    <TR><TD ALIGN = "center"><%= PR.getPurchaseRequisitionNo(i) %> </TD>
    <TD ALIGN = "center"><%= PR.getItem(i) %> </TD>
    <TD ALIGN = "center"><%= PR.getDescription(i) %></TD>
    <TD ALIGN = "center"><%= PR.getCreatorName(i)%> </TD>
    <TD ALIGN = "center"><%= PR.getPurchaseRequisitionDate(i)%> </TD>
    <TD ALIGN = "center"><%= PR.getplant(i)%> </TD>
    <% } %>
    Hope this is a simple way to get your requirement.
    Let me know if this does not help you.
    Thanks
    Kathirvel.

  • How to display uploaded images

    I have created an application that will upload a file to a
    server using Flex and C#. I would also like to display it on the
    upload form, then have a button like "are you sure you whan to
    upload this image". I do not know how to display it. Do I have an
    image container then put the source in dynamically?

    If the id of the image control is myImg then you can do so: (say you var fileReference: FileRefereence)
    myImg.source = fileReference.data

  • How can I upload file in JSP portlet?

    Hello,
    How can I upload a local file in JSP portlet? What do I have to use and where can I found infromation about that?
    Does someone has experiance in uploading file?
    Thank you!
    Kristjan

    http://jakarta.apache.org/commons/fileupload/
    http://jakarta.apache.org/commons/fileupload/using.html

  • How to display Arabic content in JSP ?

    Hi all,
    I used the following encoding method to display arabic content in JSP page.
    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    <meta content="text/html; charset=UTF-8" http-equiv="content-type"/>
    I also set -Dfile encoding=ISO-8859-6 in the JVM Options.As a result the arabic data is getting displayed .
    Variable "data" contains the actual arabic data.
    function updateArabicData(data){
    try{
    document.getElementById('divtag').innerHTML=""+data;
    }catch(err){
    <html>
    <body>
    <div id="divtag" lang="ar-sa"></div>
    </body>
    </html>
    But the problem is the arabic data getting displayed in JSP (within the <div>)seems to be jumbled up.The users say that the arabic words within a single sentence are not arranged correctly.They are mixed up.Please help me with a solution.
    Edited by: Alance on May 27, 2010 5:34 AM

    Data is retrieved as follows
    if(msg.getField("GEN_UNICODE_MESSAGE_1")!=null){
    resultString=resultString+"N"+""+new String((byte[])msg.getField("GEN_UNICODE_MESSAGE_1").value.get(0),"ISO-8859-6");
    with content Type set as response.setContentType("text/html;charset=ISO-8859-6");
    ISO-8859-6 -since the data contains arabic news.
    Edited by: Alance on May 27, 2010 11:05 PM

  • How to display stored image in jsp  in ie7???

    i am using internet explore7. i have a problem when i am displaying an image in jsp its not properly coming. this image and image is stored in database.
    image is stored in database using "binarystream" .
    i am just simply calling the image path and using the html image display tag.
    <img src="<%=fileIpath%>" but image is not coming properly but this image is showing properly in lower ie version.
    Can anyone help me???

    can anyone reply this question??Appearently no.
    It might be that the question is not interesting enough to attract people.
    Or it might be that the details you provided do no suffice and some important pieces of information are missing. For eample: what are the contents of the variable? If you save the generated page, what do you get?

  • How to Display jFrame - chart in JSP PAge

    Hi all,
    Can any one help about this task..
    I have writeen a java file which generates multiaxis chart by using JFreeChart API....
    Say for ex..
    public class multiaxis extends JFrame
    /// till know no problem...
    Can any one tell its possible to display this chart (JFrame) in Browser (JSP Page) .. any idea over this..
    Thanks in advance

    there's examples around the forums about using JFreeChart in a servlet to generate a JPEG or PNG images.

  • How to Display Seconds in a JSP file

    I want Display seconds in a SP page ,i need to alert the user that this page will be forwarded in 10 secs , so i need to display that on the page ..how can i make this happen ...can anyone throw some light on this issue ...
    Thanks
    Shyam

    Hello,
    Not sure to understand clearly what you want to do. So here some lights based on my understanding.
    So you want to see the page redirects to another location after 10sec, so in my opinion it has nothing specific to do with JSP but pure HTML development.
    1- Do the redirect
    Option 1
    On easy way is simply to put a meta-tag in the header of your page, something like
    <HEAD>
    <META HTTP-EQUIV="refresh" content="10;URL=http://blog.grallandco.com">
    </HEAD>
    Option 2
    You can also do it using Javascript:
    <script>
    function redirect()
    window.location="http://grallandco.com"
    function loadPage()
    var timer = window.setInterval("redirect()", 10000);
    </script>
    <body onLoad="loadPage();">
    2- Print the countdown
    Maybe you also want to print the countdown on the page. For this you have lot of solutions based on Javascript. I did a quick Google search on "javascript Countdowns redirect"
    Here one that looks good and easy to integrate to any page:
    Cool Redirect
    Regards
    Tugdual Grall

  • How to Display string array in jsp page using netui-data:repeater tag ??

    hi,
    I am trying to display a string array in a table using the netui-data:repeater tag.
    I have to use a page flow controller Array(1 Dimensional) to be displayed in the jsp.
    Can any one tell me how to print the array in a table of 3rows & 5 columns.
    Here is the code on which I am crrently working on.
    <netui-data:repeater dataSource="{pageFlow.strWorkObject_Array}">
    <netui-data:repeaterHeader>
    <table cellpadding="4" border="1" class="tablebody">
    </netui-data:repeaterHeader>
    <netui-data:repeaterItem>
    <tr>
    <td><netui:label value="{container.item}" >
    </netui:label></td>
    <td><netui:label value="{container.item}">
    </netui:label></td>
    <td><netui:label value="{container.item}">
    </netui:label></td>
    </tr>
    </netui-data:repeaterItem>
    <netui-data:repeaterFooter>
    </table>
    </netui-data:repeaterFooter>
    </netui-data:repeater>

    weblogic.developer.interest.workshop
    Mansoor Naseem wrote:
    I would like to know where the pageflow newsgroup is.
    These are all the groups in weblogic.developer.interest:
    weblogic.developer.interest.60beta.* (5 groups) weblogic.developer.interest.management
    weblogic.developer.interest.61beta.* (2 groups) weblogic.developer.interest.misc
    weblogic.developer.interest.clustering.* (1 group) weblogic.developer.interest.performance
    weblogic.developer.interest.commerce weblogic.developer.interest.personalization
    weblogic.developer.interest.ejb.* (3 groups) weblogic.developer.interest.portal
    weblogic.developer.interest.environment weblogic.developer.interest.rmi-iiop
    weblogic.developer.interest.jdbc weblogic.developer.interest.security
    weblogic.developer.interest.jms weblogic.developer.interest.servlet
    weblogic.developer.interest.jndi weblogic.developer.interest.tools
    weblogic.developer.interest.jsp weblogic.developer.interest.weblogicenterprise
    MN

  • How to display unicode character in jsp pages?

    i have to display user need language using unicode character according to user selected in radio button arabic or german in jsp
    pages. can you explain how i have to code?

    Hi,
    Visit the following URL http://java.sun.com/docs/books/tutorial/i18n/ .
    It will help you.
    bye for now
    sat

Maybe you are looking for

  • Helps helps Thanks for your suggestion

    I have a problem with java runtime class. I build a class which is invoked by main class. we i run it solely, which run well. but when it is invoked by main class. the runtime.excu can not finished. I have used process.waitfor, but it is no used in t

  • Bootcamp trouble and iMac will not read DVD-R with Windows

    Hi, I have a late 2011(or maybe early 2012) imac that came with OS X Lion but it's been upgraded to Mountain Lion.. I'd like to bootcamp it and install Windows 8. I've been trying this for a long time now and then i discovered my imac was not bootabl

  • Problem bluez and pulseaudio [SOLVED]

    Hi, I finished to install Arch on a Lenovo with success. The battery life is so much longer than my macbook pro, and the cpu temp are much lower. I felt I got riped off buying a Macbook pro. Well, I m still having two little errors and few things tha

  • RCU help while installing OBIEE

    Hi All, I have the following 1)Oracle DB Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production 2) OS -->win home professional 3) RCU downloaded ofm_rcu_win32_11.1.1.2.1_disk1_1of1 As my first step of creating MetaData Repository befo

  • Generating XML from dual

    Hey Gurus, I'm trying to generate the following XML from dual, however, I keep getting an error message stating my top level is not defined. Any ideas? Thanks! <PUDOOUTPUT> <PKG> <SHIPMENTID>12345</SHIPMENTID> <ERROR>'NO DATA'</ERROR> <ERRORTEXT>'Err