Hello
I have the follwing code with upload one file to "d:\\test\\testfile".
After the upload, i have opened the file "d:\\test\\testfile". it was
totally not the original file. It contains a string "upload". WHat is wrong
with mijn code.
public void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
try {
ControllerResponse res = (ControllerResponse) request.getAttribute(
Controller.RESPONSE_KEY);
FileUpload fu = new FileUpload();
// maximum size before a FileUploadException will be thrown
fu.setSizeMax(999999999);
// maximum size that will be stored in memory
fu.setSizeThreshold(4096);
// the location for saving data that is larger than getSizeThreshold()
fu.setRepositoryPath(Setup.getValueRequired(super.getDBName(request),
"TempDir"));
List fileItems = fu.parseRequest(request);
// assume we know there are two files. The first file is a small
// text file, the second is unknown and is written to a file on
// the server
Iterator i = fileItems.iterator();
FileItem fi;
String fileName;
File file;
// write the file
out.println("<html>");
out.println("<head><title>FileUpload</title></head>");
out.println("<body>");
out.println("<p>The servlet has received a POST. This is the
reply.</p>");
while(i.hasNext()){
fi = (FileItem)i.next();
fileName = fi.getName();
//file = new File(fileName);
fi.write("d:\\test\\testfile);
out.println("<p>Uploading file: " + fileName +"<p>");
}
out.println("<p>The servlet has received a POST. This is the
reply.</p>");
out.println("</body></html>");
out.flush();
} catch(DBException dbe) {
throw new ServletException("Tempory directory has not been defined in
the SETUP table", dbe);
} catch (Exception fue) {
throw new ServletException( fue);
}
}
- - - - - - - - DISCLAIMER - - - - - - - -
Unless indicated otherwise, the information contained in this message is
privileged and confidential, and is intended only for the use of the
addressee(s) named above and others who have been specifically authorized to
receive it. If you are not the intended recipient, you are hereby notified
that any dissemination, distribution or copying of this message and/or
attachments is strictly prohibited. The company accepts no liability for any
damage caused by any virus transmitted by this email. Furthermore, the
company does not warrant a proper and complete transmission of this
information, nor does it accept liability for any delays. If you have
received this message in error, please contact the sender and delete the
message. Thank you.