You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@turbine.apache.org by Jesal Doshi <je...@jalvamedia.com> on 2002/04/02 11:32:19 UTC

Upload service using Jsps

Hi
> 
> I am a new to TDK and I want to build an application having fileUpload Service.
> I would like to use fileUpload service provided by TDK.
> 
> I would like to use Jsps with tdk.
> 
> I am trying to make a fileUpload Utility which works like yahoo attachments,
> i.e. A user can select one file , then next one and so on and the selected
> files name and size gets displayed on the jsp page upon selection, Only after
> selecting all the files or one and then submitting the form on clicking Done
> the upload takes place and all the files gets uploaded to a particular
> directory on the server.
> 
> I have tried to upload a file, it works fine but at the time of uploading a
> .txt file, it shows 0 size empty file, but in case of other files like .exe,
> .zip, .log it works properly and the files are uploaded. This works fine for a
> single file upload and also the no work is done on getting the details
> displayed on the jsp page about the file selected and on successful upload
> displaying a successful message page.
> 
> Below are the settings for Upload Service of my TurbineResources.properties
> file :
> 
> # -------------------------------------------------------------------
> #
> # U P L O A D S E R V I C E
> #
> # -------------------------------------------------------------------
> 
> # Whether the files should be automatically picked up by
> # ParameterParser.
> 
> services.UploadService.automatic=true
> 
> #
> # The directory where files will be temporarily stored.
> services.UploadService.repository=./uploadedFiles
> 
> #
> # The maximum size of a request that will be processed.
> # 100 megs for now
> #
> services.UploadService.size.max=104857600
> 
> #
> # The maximum size of a request that will have it's elements cached in
> # memory by TurbineUploadService class.
> services.UploadService.size.threshold=0
> 
> Following is my java code which does the writing of the file:
> 
> public void doUpload(RunData data)
> throws Exception
> {
> FileItem fileItem = data.getParameters().getFileItem("file");
> 
> if (fileItem==null)
> {
> System.err.print("---------FileItem is null");
> return;
> }
> 
> System.out.println("**********fileItem="+fileItem.getFileName());
> String clientFilePath = fileItem.getFileName();
> System.out.println("\n -- clientFilePath : "+clientFilePath+"\n");
> String fileName = new
> String(clientFilePath.substring(clientFilePath.lastIndexOf(File.separator)+1));
> System.out.println("\n fileName is : "+fileName+"\n");
> fileItem.write(TurbineServlet.getRealPath("/uploadedFiles/"+fileName));
> }
> 
> So what should I do, so that I can do the following :
> 
> on click of a link I get the jsp which has the form for file chooser.
> on browsing a file and selecting the same and clicking add, the same page
> should get refreshed, now showing the file path, name and size of the file
> selected and allowing the user to select more files if the user wants to.
> 
> Question : How can a jsp be called passing some parameter values to it if the
> jsp call is like for e.g. as below:
> 
> <form method="post" action="<%=
> link.setPage("trial,fileUpload.jsp").setAction("trial.MAM1Upload")%>"
> enctype="multipart/form-data">
> 
> On selection of Done, all the file selected by the user should be uploaded to a
> directory in the server ( already set in the TurbineResources.proprties file. )
> 
> 
> Any help in the above context would be really great and would be highly
> appreciated.
> 
> Thanks in advance
> 
> Hope to hear soon.
> 
> Regards
> 
> Jesal