FILE UPLOAD PROBLEM SHOWING THE CONTENTS IN THE SAME BROWSER WINDOW

Hi,
This is amit Joshi
I have uploaded content using input tag of type file and posted to jsp as multipart/form-data type
in that jsp i am using following code to display the content in browser but only first content is displayed How can i modify it to show all content in the file ..
<html>
<head>
<title>File Upload Display</title>
</head>
<body>
<%
//ServletOutputStream sout=response.getOutputStream();
StringBuilder strBuilder = new StringBuilder();
int count=0;
String f;
f=request.getParameter("filedb");
DBManager dbm = new DBManager();
//dbm.createTable("mms3");
//log.info("In JSP : "+ f);
//dbm.insert_data(f,"mms3");
%>
<%
if (ServletFileUpload.isMultipartContent(request)){
ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
List fileItemsList = servletFileUpload.parseRequest(request);
strBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").append('\r').append('\n').append("<xpage version=\"1.0\">").append('\r').append('\n');
String optionalFileName = "";
FileItem fileItem = null;
Iterator it = fileItemsList.iterator();
ServletOutputStream outputStream=null;
while (it.hasNext()){
FileItem fileItemTemp = (FileItem)it.next();
if (fileItemTemp.isFormField()){
%>
<b>Name-value Pair Info:</b>
Field name: <%= fileItemTemp.getFieldName() %>
Field value: <%= fileItemTemp.getString() %>
<%
if (fileItemTemp.getFieldName().equals("filename"))
optionalFileName = fileItemTemp.getString();
else
fileItem = fileItemTemp;
if (fileItem!=null){
String fileName = fileItem.getName();
%>
<b>Uploaded File Info:</b>
Content type: <%= fileItem.getContentType() %>
Field name: <%= fileItem.getFieldName() %>
File name: <%= fileName %>
<%
if(fileItem.getContentType().equals("image/jpeg")) { %>
File : <p><%
     //response.setContentType("image/gif");
     byte[] bArray=fileItem.get();
     response.setContentType("image/jpeg");
     outputStream=null;
     outputStream= response.getOutputStream();
     outputStream.write(bArray);
     outputStream.flush();
     outputStream.close();
else if(fileItem.getContentType().equals("text/plain"))
     %> File : <%= fileItem.getString() %>
<%
byte[] bArray=fileItem.get();
response.setContentType("text/plain");
     outputStream = response.getOutputStream();
     out.println();
     outputStream.write(bArray);
     outputStream.flush();
     outputStream.close();
%> </p> <%
%>
</body>
</html>
Edited by: Amit_Joshi on Nov 13, 2007 10:58 PM

Well Well Well..
That would not work...
What you have to do is save the uploaded file content on to a location and then pass the fileName as a request parameter to a deidicated which displays the contents of that file.
Just as an example
<html>
<head>
<title>File Upload Display</title>
</head>
<body>
<%
//ServletOutputStream sout=response.getOutputStream();
StringBuilder strBuilder = new StringBuilder();
int count=0;
String f;
f=request.getParameter("filedb");
DBManager dbm = new DBManager();
//dbm.createTable("mms3");
//log.info("In JSP : "+ f);
//dbm.insert_data(f,"mms3");
%>
<%
if (ServletFileUpload.isMultipartContent(request)){
ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
List fileItemsList = servletFileUpload.parseRequest(request);
strBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>").append('\r').append('\n').append("<xpage version=\"1.0\">").append('\r').append('\n');
String optionalFileName = "";
FileItem fileItem = null;
Iterator it = fileItemsList.iterator();
ServletOutputStream outputStream=null;
while (it.hasNext()){
   FileItem fileItemTemp = (FileItem)it.next();
%>
Name-value Pair Info:
Field name: <%= fileItemTemp.getFieldName() %><br/>
Field value: <%= fileItemTemp.getString() %><br/>
<%
if (fileItemTemp.getFieldName().equals("filename"))
    optionalFileName = fileItemTemp.getString();
if(!fileTempItem.isFormFiled()){
   String fileName = fileItem.getName();
   fileItem.write(optionalFileName);
%>
Uploaded File Info:
Content type: <%= fileItem.getContentType() %><br/>
Field name: <%= fileItem.getFieldName() %><br/>
File name: <%= fileName %><br/>
<%
if(fileItem.getContentType().equals("image/jpeg") || fileItem.getContentType().equals("image/pjeg")) {
%>
  <img src="FileServlet?fileName=<%=optionalFileName%>"   
<%
%>
</body>
</html>a sample code snippet for FileServlet.
String fileName =  request.getParameter(fileName);
  File file = new File(fileName);
   if(!file.exists())
     return;
  // If JSP
  String mimeType = application.getMimeType("fileName");
       If you are using servlet
       String mimeType = this.getServletContext().getMimeType(fileName);
     response.setContentType(mimeType);  
     response.setHeader("Content-Disposition","inline;filename=\\"+fileName+"\\");
  BufferedOutputStream out1 = null;
  InputStream in = null;
  if(mimeType == null)
     mimeType = "application/octet-stream";
  try{
     in = new FileInputStream(f);
     response.setContentLength(in.available());
     BufferedOutputStream out1 = new BufferedOutputStream(response.getOutputStream(),1024);
     int size = 0;
     byte[] b = new byte[1024];
     while ((size = in.read(b, 0, 1024)) > 0)
        out1.write(b, 0, size);
  }catch(Exception exp){
  }finally{
      if(out1 != null){
         try{
            out1.flush();               
            out1.close();
         }catch(Exception e){}
      if(in != null){
        try{in.close();}catch(Exception e){}
  } Hope that might answer your question :)
However,this is not the recommended way of doing this make use of MVC pattern.Would be a better approach.
you might think of googling on this and can findout what is the best practise followed for problems of this sort
REGARDS,
RaHuL

Similar Messages

  • My I-Pad screen is black, I tried to sync and restore I-Pad, it showes the contents on the computer and pulling out pictures and other files, but screen is black. what can I do?

    My I-Pad screen is black!! I tried to sync and restore I-Pad, it showes the contents on the computer and pulling out pictures and other files, but screen is black. I don't know what happened! what can I do?

    I have this problem as well...however, resetting/restoring did not take place when I followed the same instructions but got nothing on the screen.  Thanks in advance.

  • How to read the contents of the Uploaded file ?

    hi @,
    I have used the File upload and Download UI elements as per the tutorial available. Now my requirement is to read the contents of the file and transfer it to the Backend system.
    How can I achieve the desired fucntionality.
    Thanks in advance,
    Regards,
    Amit

    try this code to store image file in back end system.
    IWDResource res=wdContext.currentMyDataElement().getPictureres();
              InputStream in=res.read(false);
              ByteArrayOutputStream bout=new ByteArrayOutputStream();
              int length;
              byte[] part=new byte[10*1024];
              while((length=in.read(part))!=-1)
              bout.write(part,0,length);
              in.close();
    pstmt.setBytes(8,bout.toByteArray());
    If it is other than image file like word or text then try this in action
    IWDResource resource = wdContext.currentResElement().getResorce(); // your existing handle to the upload resource type
                try {
                   InputStream stream = resource.read(true);
                   byte b[]= new byte[1000];
                   stream.read(b);
                   String str = new String(b);
                   int i=str.length();
                   wdContext.currentContextElement().setOut(str);
                   wdContext.currentContextElement().setSize(i);
                   wdContext.currentResElement().setResourceurl(
                        wdContext.currentResElement().getResorce().getUrl(WDFileDownloadBehaviour.OPEN_INPLACE.ordinal()));
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    The in back end field where u store the file should be byte array.
    Regards,
    H.V.Swathi

  • How to get the content of the uploaded file.

    Hi Experts,
    I am using a input box to get the path of the file to be uploaded.(I am not using FILE UPLOAD UI Element).Could you please let me know how to get the content of the uploaded file.
    Regards,
    Arun

    >
    ARUN KUMAR.S wrote:
    > Hi Experts,
    >
    > I am using a input box to get the path of the file to be uploaded.(I am not using FILE UPLOAD UI Element).Could you please let me know how to get the content of the uploaded file.
    >
    > Regards,
    > Arun
    You will not be able to use a normal InputField to upload file contents.  This is not allowed by the browser security model. You must use one of the upload specific UI mechanisms - the FileUpload UI element or as of 7.01 ACFUpDownload or FlashIslands.

  • Have been trying all weekend to upload Jpegs- either Send does not work or shows files uploading then shows error- never had this problem with Send Now-16 images total size 92MB-largest image 13MB

    Have been trying all weekend to upload Jpegs- either Send does not work or shows files uploading then shows error- never had this problem with Send Now-16 images total size 92MB-largest image 13MB

    Hi Ciaran19,
    Are you sending files from the Adobe Send interface, Adobe Reader, or the Outlook plug-in?
    Have you checked to see whether the files that you're sending appear in the Recent Files/Sent Files list when you're logged on to https://cloud.acrobat.com? (It could be that they're uploading, but not being sent.)
    It would also be worthwhile to send the files in smaller batches, to see whether a particular file or files is problematic, and causing the error.
    Please let us know how it goes. If you're still having trouble, please let us know where you're sending from, and whether you're able to send the files in smaller batches. It would also be helpful to know the exact error message that you're receiving.
    Best,
    Sara

  • I am having problems with mail after upgrading to snow leopard. When I send an email to somebody, I would get a reply from them but the content of the reply were old emails from months ago. Any ideas what's going on?

    For ex. The subject of my email was "List of kids dancing this weekend". Then i would compose my email and send it to the recepient. They responded to my email with the same subject "List of kids dancing this weekend" but the content of the email was the email I received from somebody else months ago. This "phenomenon" happened serveral times already. Please help!

    Check this post out
    http://hints.macworld.com/article.php?story=20110516152604993
    Turns out the auto-complete database is a SQLite DB stored in this folder.  Probably the ownership and/or permissions are messed up on your system.  Mine (under Snow Leopard) show  ownership by me and rw privilege for all files in that directory, including MailRecents....

  • I have one out of five email address's with coxmail that opens with a blank inbox but other browsers show the content of the same inbox

    Question
    I have one out of five email address's with coxmail that opens with a blank inbox. Other browsers like opera or IE show the content of the same inbox. I've contacted cox but they tell me the problem is on my computer. I've used three different anti virus/malware scanners to eliminate all the bugs they can find. I need a firefox guru with suggestions. Thanks, Charles

    You can undo your permission changes. Probably the most relevant one is cookies. Try one or both of these methods:
    (1) Page Info > Permissions tab
    While viewing a page on the site:
    * right-click and choose View Page Info > Permissions
    * Alt+t (open the classic Tools menu) > Page Info > Permissions
    (2) about:permissions
    In a new tab, type or paste '''about:permissions''' and press Enter. Allow a few moments for the list on the left to populate, as this information needs to be extracted from a database.
    Then type or paste ''rcn''' in the search box above the list to filter it to the most relevant domains. When you highlight a domain, you can adjust its permissions in the right pane.
    Any luck?

  • Version 5.0 on a MAC will not let me switch between tabs. I can open a new tab, but when I try to go to a different tab, it just shows me the contents of the tab most recently opened. Help!

    Version 5.0 on a MAC will not let me switch between tabs. I can open a new tab, but when I try to go to a different tab, it just shows me the contents of the tab most recently opened. Help!
    Also, pop up blocker works for some time and then just stops working. I have to close and restart Firefox to get it to work again. Help!

    I had the same problem, but with Firefox 4.0. My first thought was to update Firefox (after of course restarting FF), but that didn't help it and I had the same problem.
    Among others, I had an extension installed and enabled called Tile Tabs 4.10 that I thought could feasibly creating this problem. So I went into my add-ons manager and disabled it, restarted Firefox and the tabs worked properly again. Unfortunately, the Tile Tabs extension is my favorite Firefox add-on and I use it almost every day for managing my web work tasks. I went to the add-on page for Tile Tabs and saw that there was a notice that version 4.10 didn't work properly on Mac OS, and to install version 4.9 of the extension. I saw they had a new, not-yet-reviewed version 4.11 that addressed the Mac OS problem, installed it, and everything seems to be working properly.
    I have no idea why all of a sudden I had this problem, as I hadn't updated Firefox or the Tile Tabs extension recently. Also, obviously this might not address your problem, especially if you don't have that add-on installed and enabled. But our problem started at the same time for both of us it appears based on your post time, so its probably not coincidence.
    But its worth a look, and you might want to check out other extensions if you don't have Tile Tabs that could be causing the problem.

  • Using an external drive with shared files (iPhoto, iTunes), attached to a Time Capsule, can the contents of the external drive be backed-up to the internal Time Capsule drive? Perhaps a RAID1 mirror to a partition?

    Using an external drive with shared files (iPhoto, iTunes), attached to a Time Capsule, can the contents of the external drive be backed-up to the internal Time Capsule drive? Perhaps a RAID1 mirror to a partitioned Time Capsule? I understand that the Time Machine (software) cannot backup a networked drive (the external) and that Time Capsule (the router/wireless hard drive) does not have its own backup software... so it won't backup the connected drive. What I would like is an alternate solution for having an automated backup of a networked drive. A 2TB Time Capsule has more than enough space for Time Machine backups of my family of Macbooks, so I had hoped to mirror a 500GB external drive (with shared media files) to a portion of the Time Capsule internal hard drive. I assume this would require a partition of the Time Capsule drive. If not, would the sparse file from the various computers being backed up need to be copied to the external drive as part of the RAID1 setup? This seems like overkill for the Time Machine backup, but it would cover the media files.  

    The complexity with this idea is the software has to run from a Mac computer on your network.. so you need a Mac turned on, probably most of the day.
    It isn't possible to partition the TC although you can create a image area.
    The software would have to copy the material, that means all files to be copied, go from USB drive, back to the Mac, then back to the TC, and written to the drive. In other words you have just added Network congestion, although a proper incremental backup type software will not actually use a lot of capacity.
    Finally it will be slow.. network drives are slower than internal drives. Well USB connected drive is much slower than the same drive connected directly to the computer.. and if the drive is connected directly to a computer it can be shared with the network.
    http://www.anandtech.com/show/4577/airport-extreme-5th-gen-and-time-capsule-4th- gen-review-faster-wifi-/4
    Read carefully the speed of the USB drive plugged into the TC.

  • Get the content from the PDF file IN WD ABAP View

    Hi all,
    I have a offline interactive form with data filled in that and save in my desktop. I want to upload the PDF content ( data ) into Web dynpro view.
    Currently i have the view designed with all the input box bound with the respective fields in the context and these fields are same as Adobe form fields.
    I have a UI element to browse and pick the file from the desktop. I have the upload button to upload the data into it.
    When i click the upload button it goes for dump. " No Enough Information for processing or Output"
    *Get the content from the file
      WD_CONTEXT->GET_ATTRIBUTE( EXPORTING NAME = 'PDFSOURCE'  IMPORTING VALUE = CONTENT ).
    In the above statement CONTENT is initial.  Hence dump. I have take this source from SDN Blog.
    Kindly help me where i went wrong.
    Thanks in advance.I

    Hi,
    try my solution (reading dunamic table, but you can read any data from pdf xml) described here:
    Dynamic Table data cannot be Read.
    Regards Jiri

  • Iphoto has just deleted the contents of the last album i uploaded by unexpectedly closing whilst viewing photos. It is also refusing to recognise "flagged" photos. any ideas?

    iphoto has just deleted the contents of the last album i uploaded by unexpectedly closing whilst viewing photos. It is also refusing to recognise "flagged" photos. any ideas?

    Option 1
    Back Up and try rebuild the library: hold down the command and option (or alt) keys while launching iPhoto. Use the resulting dialogue to rebuild. Choose to Repair Database. If that doesn't help, then try again, this time using Rebuild Database.
    If that fails:
    Option 2
    Download iPhoto Library Manager and use its rebuild function. (In early versions of Library Manager it's the File -> Rebuild command. In later versions it's under the Library menu.)
    This will create an entirely new library. It will then copy (or try to) your photos and all the associated metadata and versions to this new Library, and arrange it as close as it can to what you had in the damaged Library. It does this based on information it finds in the iPhoto sharing mechanism - but that means that things not shared won't be there, so no slideshows, books or calendars, for instance - but it should get all your events, albums and keywords, faces and places back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one.  
    Regards
    TD

  • When I receive messages with attachments, the contents of the attachment also show up in the body of the text. Anyway to prevent that? Thx

    Example, excel file shows as an attachment, and can be opened as an attachment...but the contents of the excel file are also included in the body of the email. Same happens with jpegs. thx

    ''sc344 [[#question-1057671|said]]''
    <blockquote>
    Example, excel file shows as an attachment, and can be opened as an attachment...but the contents of the excel file are also included in the body of the email. Same happens with jpegs. thx
    </blockquote>
    correcting my example - the files are text files (txt) and jpegs - not excel files.

  • Can we control the PDF file name that is generated by BI Publisher based on the content in the input PDF

    can we control the PDF file name that is generated by BI Publisher based on the content in the input PDF?

    No, there isn't. The way you're using the file is not recommended. You
    should use a review tracker to avoid getting in the way of one another.

  • How to read the contents in the excel file on the basis of colunm heading?

    Hi,
    Here is my requirement like that  in excel file i got the customer number , amount etc....
    And my required fields are customer and amount. In file customer nr is under the heading 'CUSTOMER' and amount is under the heading 'AMOUNT'.
    Is there any FM for reading the contents under the colunm heading of excel?
    Please suggest me.
    Thanks,
    Harshal kulkarni

    Hi Harshal ,
    I dont think there is such function module /BAPI/Class-Method .
    but if your excel file is dynamic you can write your own logic using field - symbols.
    Regards ,
    Praveen

  • Just got a new mac computer and none of the music from my old computer's itunes transfered when I transfered the contents of the hard drive.  Now I'm trying to transfer music from my ipod and can't get all the files....help?

    Just got a new  computer and none of the music from my old computer's itunes transfered when I transfered the contents of the old hard drive.  Now I'm trying to transfer music from my ipod and can't get all the files....help please?

    The iphone is not a storage/backup device.
    It has always been very basic to always maintain a backup copy of your computer for this very occasion.
    Have you failed to do this?
    If so, not good, then you can transfer itunes purchases:  File>Devices>Transfer Purchases
    You may be able to purchase a third partyn program to get the rest ( not supported by Apple)

Maybe you are looking for