ug

Dec 26, 2004 03:31

So, I'm currently attempting to make a nice and neat little web-app with java to take care of letting my mother upload stuff onto her website without me having to upload it for her.

Edit: I'm very obviously ripping off the demo code that came with FileUpload. I'm also being too damn lazy to clean up the now-nonsensical comments. My appologies.


I have two files up.jsp and multipart.jsp... I've been hacking at them all evening so I'm going to give up now nad sleep. If anyone else could look at them, I'd really appreciate it.

up.jsp simply looks like this:

--!>

Here's multipart.jsp:

<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.apache.commons.fileupload.*" %>

<%! String blarg(HttpServletRequest req, HttpServletResponse res)
{
if(req != null)
{
DiskFileUpload fu = new DiskFileUpload();
// maximum size before a FileUploadException will be thrown
fu.setSizeMax(1000000);
// maximum size that will be stored in memory
fu.setSizeThreshold(4096);
// the location for saving data that is larger than getSizeThreshold()
fu.setRepositoryPath("/tmp/");

List fileItems = fu.parseRequest(req);
// 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 = (FileItem)i.next();
// filename on the client
String fileName = fi.getName();
// write the file
// fi.write(new File("/tmp/" + fileName));
//return "Finished.";
return fileName;
}
else
{
return "NULL!!!";
}
} %>
<%= blarg(request, response) %>

It's throwing a FileUploadException, which, according to the docs, is pretty much only supposed to happen when either the file I'm attempting to upload is too damn big (in this case, greater than 10MB) or if the DiskFileUpload couldn't parse the Httprequest...

Now, I'm not very good at ALL with JSPs.... I'm willing to bet GOOD MONEY that I'm screwing something very very basic up here. Anyone gots any clues?

-wik
Previous post Next post
Up