Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Installation

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-13-2008, 12:18 PM
New Member
 
Posts: 3
Default How display a image on Servlet from a File Upload

My requirement is I want to display a Image on Servlet from File Upload.
But It not display on servlet,Its appear a downloaded form and downloaded on disk when click on save button.Other thing is that It not a .jpg form.that mean It does not open by photo gallery.that message show file format not supported by Photo Gallary.
I also install I the Live HTTP headers 0.14 from Google in Firefox.
I run the weblogic on Firefox and run that progarm but same issue persist.
I also used Internet Browser,but problem are not solved.
I already download comman-file upload-1.2.1.jar and comman-io-1.4 in lib folder and set this on classpath.
Here my files:
Home.html:
Code:

File
UploadFile.java:
Code:
import java.io.*;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.FileUpload;
import org.apache.commons.fileupload.FileUploadException;
import javax.activation.DataSource;
public class UploadFile extends HttpServlet {
public void doPost(HttpServletRequest req,HttpServletResponse res)
{
try{
FileUpload fup=new FileUpload();
boolean isMultipart = FileUpload.isMultipartContent(req);
// Create a new file upload handler
System.out.println(isMultipart);
DiskFileUpload upload = new DiskFileUpload();
// Parse the request
List items = upload.parseRequest(req);
Iterator iter = items.iterator();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
InputStream in=item.getInputStream();
int len = req.getContentLength();
System.out.println("Running Starting");
System.out.println("*************");
System.out.println("Length is: "+len); 
System.out.println("+++++++++++");
byte [] dataBytes = new byte[len]; 
int index=in.read(dataBytes, 0, len);
System.out.println("********");
System.out.println("index"+index);
System.out.println("+++++++++");
// res.reset();
res.setContentType("image/jpg");
res.setHeader("Content-Disposition", "attachment; filename=\"image.jpg\"");
System.out.println("One image writting");
res.getOutputStream().write(dataBytes,0,len);
res.getOutputStream().flush(); 
System.out.println("Suceesfully send");
}
}
catch(Exception e){System.out.println(e);}
}
}
web.xml:
Code:


one
UploadFile


one
/tmp


Home.html

Please Help me..
Reply With Quote
  #2 (permalink)  
Old 12-13-2008, 12:42 PM
Zimbra Consultant & Moderator
 
Posts: 20,316
Default

Where in Zimbra are you trying to do this, in a zimlet?
__________________
Regards


Bill
Reply With Quote
  #3 (permalink)  
Old 12-13-2008, 01:37 PM
New Member
 
Posts: 3
Default Please let me

Quote:
Originally Posted by phoenix View Post
Where in Zimbra are you trying to do this, in a zimlet?
what mean Sir,
Please simplyfy.
Have I post my question in wrong place..??
Reply With Quote
  #4 (permalink)  
Old 12-13-2008, 01:44 PM
OpenSource Builder & Moderator
 
Posts: 1,166
Default

yes, this is a forum for a product called Zimbra. you are in the wrong place.
Reply With Quote
  #5 (permalink)  
Old 12-13-2008, 01:59 PM
New Member
 
Posts: 3
Default Please let me know

Quote:
Originally Posted by dijichi2 View Post
yes, this is a forum for a product called Zimbra. you are in the wrong place.
Dear Sir,
Can you write me please where I put java related query on this site.
please let me know.
Reply With Quote
  #6 (permalink)  
Old 12-13-2008, 03:46 PM
OpenSource Builder & Moderator
 
Posts: 1,166
Default

This forum has nothing to do with Java development. Try google.com
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.