Ji Rong Hu,
The file upload example you are using is old and uses the deprecated (or at
least not recommended to use) getFileData() method. The recomended method
is to use the getInputStream() method to obtain an input stream to the form
file and read it that way. I attached the newer UploadAction source file
that uses this method. You can find this in any recent build of Struts.
-----Original Message-----
From: Ji Rong Hu
To: [EMAIL PROTECTED]
Sent: 2/21/01 10:45 PM
Subject: Re: File Upload
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,
ActionForm form,
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.
UploadAction.java