从
EXCEL到数据库,引入poi.jar
jsp如下
Servlet如下
jsp如下
点击(此处)折叠或打开
- <form enctype="multipart/form-data" name=testform method=post action=Testaction>
- <table>
- <tr>
- <td><font size=2>批量上传:</font><input type="file" name="test" size="10"><br></td>
- <td><input type="submit" name="批量上传" size="10"value="批量上传"><br></td></tr></table><br>
- </form>
点击(此处)折叠或打开
- package control;
-
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.PrintWriter;
- import java.io.RandomAccessFile;
-
- import javax.servlet.ServletException;
- import javax.servlet.http.HttpServlet;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
-
- public class Testaction extends HttpServlet {
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
-
-
- }
-
- /**
- * The doPost method of the servlet. <br>
- *
- * This method is called when a form has its tag value method equals to post.
- *
- * @param request the request send by the client to the server
- * @param response the response send by the server to the client
- * @throws ServletException if an error occurred
- * @throws IOException if an error occurred
- */
- public void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- //接收上传文件内容中临时文件的文件名
- String tempFileName = new String("tempFileName");
- //tempfile 对象指向临时文件
- File tempFile = new File("D:/"+tempFileName);
- //outputfile 文件输出流指向这个临时文件
- FileOutputStream outputStream = new FileOutputStream(tempFile);
- //得到客服端提交的所有数据
- InputStream fileSourcel = request.getInputStream();
- //将得到的客服端数据写入临时文件
- byte b[] = new byte[1000];
- int n ;
- while ((n=fileSourcel.read(b))!=