MultipartRequest File Upload
I'm trying for ages to get a working fileupload system with a variable name. I've searched the entire web for a nice (not too difficult) example but there doesn't seems to be one. I've been trying to get a working one and im this far atm. I thought that it should work but i keep getting a weird error. Weird, coz to me its standing there correct. Could anyone tell me what is wrong in this code or supply me with another 'working' version of a fileupload that's understandable for an amateur JSP programmer.
The error i get is this:
Error creating file: java.io.IOException: Posted content type isn't multipart/form-data
Here's my code:
<%@ page language="java" contentType="text/html" import = "java.io.*" import = 'com.oreilly.servlet.*' %>
<%@ page import="com.oreilly.servlet.MultipartRequest" %>
<%@ page import="java.util.*" %>
<html>
<head>
<title>Project Gosu</title>
<%
String urlred = "loginfailure.htm";
String name = (String) session.getAttribute( "Sessie" );
if( name != null )
{
out.println( "Hello "+name+"!" );
}
if(name == null)
{
response.sendRedirect(urlred);
}
try
{
MultipartRequest mrequest = new MultipartRequest(request, "C:/jakarta-tomcat-3.2.4/webapps/ProjectGosu/Login/Replays");
Enumeration files = mrequest.getFileNames();
while(files.hasMoreElements() )
{
String upload = (String)files.nextElement();
String filename = mrequest.getFilesystemName(upload);
System.out.println(filename);
}
}
catch(Exception ex)
{
System.out.println("Error creating file: " + ex );
}
%>
</head>
<body LINK="#000000" VLINK="#000000" ALINK="#000000">
<table width="984" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="128" colspan="3" bgcolor="F1ECE9"><img height="128" width="1024" src="../Tryout_Pic.jpg"></td>
</tr>
<tr>
<td height="640" width="184" bgcolor="F1ECE9" valign="top">
<img height="8" width="6" src="Hyperlink_pic.jpg"> <a href="../index.jsp" title="Index">Index</a><br>
<img height="8" width="6" src="Hyperlink_pic.jpg"> <a href="main.jsp" title="Main">Main</a><br>
</td>
<td width="616" height="640" valign="middle">
<form name="frm" method="post" action="main.jsp" enctype="multipart/form-data">
<table align="center">
<tr>
<td>File
</td>
<td><input type="File" name="myupload">
</td>
</tr>
<tr>
<td>
</td>
<td><input type="submit" value="Insert">
</td>
</tr>
</table>
</form>
</td>
<td width="184" height="640" bgcolor="F1ECE9" valign="top" align="center">
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
|