求 jsp servlet+JavaBean+SQL 写一个文件上传程序

天更蓝 发布于 2014/06/21 17:50
阅读 350
收藏 0

用MyEclipse编写

加载中
0
pantrick
pantrick
与xxclipse 没人任何关系,纯servlet可能有点困难,上传需要解析二进制头,用apache jakatar 的fileupload组件,一个servlet就搞定了,与sql也没多大关系!
天更蓝
能给出具体代码吗?就用servlet编写上传到数据库!谢谢!
0
pantrick
pantrick
<form method="POST" enctype="multipart/form-data" action="fup.cgi">   File to upload: <input type="file" name="upfile"><br/>   Notes about the file: <input type="text" name="note"><br/>   <br/>   <input type="submit" value="Press"> to upload the file! </form>

boolean isMultipart = ServletFileUpload.isMultipartContent(request);


// Create a factory for disk-based file items DiskFileItemFactory factory = new DiskFileItemFactory(); // Configure a repository (to ensure a secure temp location is used) ServletContext servletContext = this.getServletConfig().getServletContext(); File repository = (File) servletContext.getAttribute("javax.servlet.context.tempdir"); factory.setRepository(repository); // Create a new file upload handler ServletFileUpload upload = new ServletFileUpload(factory); // Parse the request List<FileItem> items = upload.parseRequest(request);
下面是文档地址,很简单

http://commons.apache.org/proper/commons-fileupload/using.html

返回顶部
顶部