------JSP页面<%@ page language="java" pageEncoding="utf-8"%><html>
<head>
<title>上传文件</title> <script type="text/javascript">
<!--
function upload(){
var form = document.forms[0];
form.submit();

//-->
</script>
</head> <body>
<form action="upload" method="post">
<table>
<tr>
<td>
<input type="file" id="fileId" name="fileId" />
</td>
</tr>
<tr>
<td>
<input type="button" id="button" value="提交" onclick="upload()"/>
</td>
</tr>
</table>
</form>
</body>
</html>
------Servlet类
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;/**
 * 上传文件存储本机
 */
public class UploadServlet extends HttpServlet { /**
 * POST提交方式
 */
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

//获取页面上传的文件路径
String filePath = request.getParameter("fileId");
System.out.println("文件路径 == "+filePath);

//字节输入流读文件
InputStream is = null;
//字节输出流写文件
OutputStream os = null;
try{
//创建文件对象
is = new FileInputStream(new File(filePath));
//参数为读取文件后写入本机的位置,这里你可以自己处理盘(F盘)、文件名(text)、后缀(.txt)
os = new FileOutputStream("F:/文件名.后缀");
byte buff[] = new byte[1024];
int byteSize = 0;
while((byteSize = is.read(buff)) != -1){
os.write(buff, 0, byteSize);
}
//清空缓冲区,关闭流
os.flush();
is.close();
os.close();
}
catch(IOException e){
System.out.println("IO异常");
}
catch(Exception e){
System.out.println("运行时异常");
}
}
}说明:已经测试通过。
   注意事项一:上传的文件名如果一样的话,会覆盖以保存文件
   注意事项二:清空缓冲区,关闭流的顺序不知道有没有什么特殊的要求没
哪里有误望各位大虾们扶正,谢谢