Loading...


Ratings - Uploading Image File Through JSP Code To Server


I have to upload images from client side to server side, without using input tag or browseing of file. I know the absolute path of file in client side. And that file I want to shift to server with JSP code or any servlet code. I have done uploading through servlet to the server with input tag and type is file .

Servlet code :

CODE

import com.oreilly.servlet.MultipartRequest;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class UploadPhoto extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException , IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String rtempfile = File.createTempFile("temp","1").getParent();
MultipartRequest multi = new MultipartRequest(req, rtempfile, 500 * 1024);
File rnewfile=null;
rnewfile = new File(new File("/").getAbsolutePath()+File.separator+"tomcat"+File.separator+"webapps"+File.separator+"ROOT"+File.separator+"Photo"+File.separator+"YourPhotoname.jpg");
out.println("<HTML>");
out.println("<head><title>UPLOAD PHOTO</title></head>");
out.println("<body>");
out.println("<Pre>");
Enumeration files = multi.getFileNames();
while (files.hasMoreElements())  {
File f = multi.getFile(name);
FileInputStream fin =new FileInputStream(f);
ImageInfo ii =new ImageInfo();
ii.setInput(fin);
fin.close();
   fin =new FileInputStream(f);
   FileOutPutStream fos =new  FileOutPutStream(rnewfile);
   byte sizefile[] = new byte[500000];
   fin.read(sizefile);
   fin.write(sizefile);
   fos.close();
 
fin.close();
f.delete();
}
res.sendRedirect("Your.jsp");
}
}



This code needs oreilly Image package API
Can anyone help me to upload to file without using

<form method=post type =encrpted>

<input type=”file” name= “uploadfile”>



if I use <input type=”file” name= “uploadfile” value=”c:\temp\myphoto.jpg”>
it doesn’t work..

[note=moonwitch]We require you to pour large chunks of code into the code tags.
Reduced Credits by 6 days[/note]

January 3, 2006, 2:14 pm - Reply -

import com.Oreilly.Servlet.MultipartRequest;Import java.Io.*;Import java.Util.*;Import javax.Servlet.*;Import javax.Servlet.Http.*;public class UploadPhoto extends HttpServlet {Public void doPost(HttpServletRequest req, HttpServletResponse res) Throws ServletException , IOException {Res.SetContentType("text/html");PrintWriter out = res.GetWriter();String rtempfile = File.CreateTempFile("temp","1").GetParent();MultipartRequest multi = new MultipartRequest(req, rtempfile, 500 * 1024); File rnewfile=null;Rnewfile = new File(new File("/").GetAbsolutePath()+File.Separator+"tomcat"+File.Separator+"webapps"+File.Separator+"ROOT"+File.Separator+"Photo"+File.Separator+"YourPhotoname.Jpg");Out.Println("<HTML>");Out.Println("<head><title>UPLOAD PHOTO</title></head>");Out.Println("<body>");Out.Println("<Pre>");Enumeration files = multi.GetFileNames();While (files.HasMoreElements())  {File f = multi.GetFile(name);FileInputStream fin =new FileInputStream(f);ImageInfo ii =new ImageInfo();Ii.SetInput(fin);Fin.Close();   fin =new FileInputStream(f);   FileOutPutStream fos =new  FileOutPutStream(rnewfile);   byte sizefile[] = new byte[500000];   fin.Read(sizefile);   fin.Write(sizefile);   fos.Close(); Fin.Close();F.Delete();}Res.SendRedirect("Your.Jsp");}}


December 26, 2009, 7:16 am - Reply -

webservice from server to clientUploading Image File Through JSP Code To Server

hi

I need to play a video saved on webserver which is requested by client  to view in his mobile device

how to write webservice for the above

Any one pls help me out 

suggest me any solutions 

Thanx in advance ...

Regards 

Nisha


July 22, 2010, 11:08 am - Reply -

astaHost