小弟这里有一个自己写的文件上传的code,不知道你是不是用的上哈,你自己看一下:
UploadServlet.java:import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class UploadServlet extends HttpServlet { /**
 * 
 */
private static final long serialVersionUID = 1L; public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//取得bundary
String contentType = request.getHeader("Content-Type");
String bundary = null;
if(contentType != null && contentType.startsWith("multipart/form-data;") ){
bundary = "--" + contentType.substring("multipart/form-data; boundary=".length());
}
ServletInputStream sis = null;
OutputStream os = null;
try{
//对body进行处理
sis = request.getInputStream();

byte[] buf = new byte[1024];
int len = -1;

sis.readLine(buf, 0, 1024); //bundary行

//取得文件名
len = sis.readLine(buf, 0, 1024); //Content-Disposition行
String fileNameLine = new String(buf, 0, len, "GB18030");
String fileName = fileNameLine.substring(fileNameLine.lastIndexOf("\\")+1, fileNameLine.length()-3);
System.out.println(fileName);

sis.readLine(buf, 0, 1024); //Content-Type行
sis.readLine(buf, 0, 1024); //文件内容之前的空行

//把文件内容写出去
os=new FileOutputStream(new File("D:\\upload\\" + fileName));
//以下注释的四行是为了解决文本文件多一空行的问题
//len = sis.readLine(buf, 0, 1024);
//os.write(buf, 0, len - 2);
while( (len = sis.readLine(buf, 0, 1024)) != -1){
String line = new String(buf, 0, len, "GB18030");
if(!line.startsWith(bundary)){
//os.write("\r\n".getBytes());
//os.write(buf, 0, len - 2);
os.write(buf, 0, len);
}else{
break;
}
}
}finally{
os.close();
sis.close();
}
}
}这是访问的html页面:index.html:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>index.html</title>
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=GB18030">    
    <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
  </head>  
  <body>
    please select your file to upload<br>
    <form action="UploadServlet" method="post" enctype="multipart/form-data">
     <input type="file" name="file01"><br>
     <input type="submit" value="上传">
    </form>
  </body>
</html>web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  <servlet>
    <servlet-name>UploadServlet</servlet-name>
    <servlet-class>UploadServlet</servlet-class>
  </servlet>  <servlet-mapping>
    <servlet-name>UploadServlet</servlet-name>
    <url-pattern>/UploadServlet</url-pattern>
  </servlet-mapping>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
  </welcome-file-list>
</web-app>
大概就是这样了,至于存数据库的工作就你自己在做了,D:\\upload这个文件你得先创建出来,这样就可以了。