Re: File Upload

2001-02-21 Thread Ji Rong Hu



Thanks for all you helps.

Just for your information. My version of that sample will not work because there
is a duplicated tag in struts-html.tld,
=
attribute
nameimageName/name
requiredfalse/required
rtexprvaluetrue/rtexprvalue
/attribute
==
delete either one will work.

Jirong










"Craig R. McClanahan" [EMAIL PROTECTED] on 02/22/2001 10:30:40 AM

Please respond to [EMAIL PROTECTED]





  
  
  
 To:  [EMAIL PROTECTED]  
  
 cc:      (bcc: Ji Rong Hu/Singapore/Netlife) 
  
  
  
 Subject: Re: File Upload 
  








There is a complete example application using file upload in the
"struts-upload.war" file -- check in the "webapps" directory.

Craig McClanahan


Ji Rong Hu wrote:

 Hi, can anyone give me an example on file uploading within Struts?
 Thanks,
 Jirong




Disclaimer  :

The information contained in this email is intended solely for the addressee.
Access to this email by anyone else is unauthorized. If you are not the intended
recipient, any form of disclosure, reproduction, distribution or any action
taken or refrained from in reliance on it, is prohibited and may be unlawful.
Please notify the sender immediately. The content of this email is not legally
binding unless confirmed by letter. The sending of emails to us will not
constitute compliance with any time limits or deadlines. We also like to inform
you that communication via email over the internet is insecure because third
parties may have the possibility to access and manipulate emails.







Re: File Upload

2001-02-21 Thread Ji Rong Hu



Hi, guys, I am going to lunch. I think it's wise to use this time to just ask
before I doing a test, can anyone tell me that:

is these data, include file data, still avaiable in HttpServletRequst object?
Why, because out old EJB object extract these data from HttpServletRequst.

Thanks,
Jirong


The following is the "upload" example which enables you get these info from Form
bean.
=

public class UploadAction extends Action {

 public ActionForward perform(ActionMapping mapping,
 ActionFormform,
 HttpServletRequest request,
 HttpServletResponse
response) {

  if (form instanceof UploadForm) {

   UploadForm theForm = (UploadForm) form;

   //retrieve the text data
   String text = theForm.getTheText();

   //retrieve the file representation
   FormFile file = theForm.getTheFile();

   //retrieve the file name
   String fileName= file.getFileName();

   //retrieve the content type
   String contentType = file.getContentType();

   //retrieve the file size
   String size = (file.getFileSize() + " bytes");

   String data = null;

   try {
//retrieve the file data
data = new String(file.getFileData());
   }
   catch (FileNotFoundException fnfe) {
return null;
   }
   catch (IOException ioe) {
return null;
   }

   //place the data into the request for retrieval from display.jsp
   request.setAttribute("text", text);
   request.setAttribute("fileName", fileName);
   request.setAttribute("contentType", contentType);
   request.setAttribute("size", size);
   request.setAttribute("data", data);

   //destroy the temporary file created
   file.destroy();

   //return a forward to display.jsp
   return mapping.findForward("display");
  }

  //this shouldn't happen in this example
  return null;
 }




Disclaimer  :

The information contained in this email is intended solely for the addressee.
Access to this email by anyone else is unauthorized. If you are not the intended
recipient, any form of disclosure, reproduction, distribution or any action
taken or refrained from in reliance on it, is prohibited and may be unlawful.
Please notify the sender immediately. The content of this email is not legally
binding unless confirmed by letter. The sending of emails to us will not
constitute compliance with any time limits or deadlines. We also like to inform
you that communication via email over the internet is insecure because third
parties may have the possibility to access and manipulate emails.