- 浏览: 133546 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
xiaojiit:
99九夜茴 写道请问能不能把服务器端是Java的Web传我一下 ...
C# 编程WinForm 上传文件到 Asp.Net 的 Web项目 -
99九夜茴:
请问能不能把服务器端是Java的Web传我一下啊?我把代码复制 ...
C# 编程WinForm 上传文件到 Asp.Net 的 Web项目 -
xiaojiit:
不好意思,忘记传了。
Web通用简体繁体转化Js -
wwwcomy:
Language.js他人呢
Web通用简体繁体转化Js -
xiaojiit:
luogen33 写道 这美眉 很强悍啊!!哈哈,过奖过 ...
Java 获取系统信息,包括CPU使用率、硬盘大小、网卡状态、系统信息等
<wbr> </wbr><wbr> </wbr><wbr>今天做JSP的网页,遇到一下传文件的问题,从网上搜了搜,可以实现文件上传,但是没有办法将File表单和其它表单的信息同时获取,但这是经常遇到的问题,所以,自己研究一下,其实挺简单的。
</wbr><wbr>我们利用的是Common-fileupload组件,需要两个包:commons-fileupload-1.2.jar和commons-io-1.3.2.jar这两个包,可以从它的官方去下载(里面有doc和src)。
</wbr><wbr>另外,我们还需要在WebRoot目录下,新建两个文件夹,ImagesUploadTemp 和upload。其中,我们将上传的文件放到upload目录下边。
</wbr><wbr>下面就开始进行操作吧:
</wbr><wbr>首先呢,得有个上传页面吧,文件如下:
</wbr><wbr><form name="form1" method="post" action="FileUploadServlet" enctype="multipart/form-data">
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> <table width="619" height="562" border="1" >
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> <tr>
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> <td width="146" height="35">用户名:</td>
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> <td width="454">
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> <input name="name" type="text" id="name">
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </td>
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </tr>
<tr>
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> <td width="146" height="35">密码:</td>
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> <td width="454">
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> <input name="password" type="password" id="name">
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </td>
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </tr></wbr>
<wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr><tr>
</wbr><wbr> </wbr><wbr><td width="140" height="38">图片:</td>
</wbr><wbr> </wbr><wbr> </wbr><wbr><td width="447">
</wbr><wbr> </wbr><wbr> </wbr><wbr><input type="file" size="30" name="test" /> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr><input type="submit" name="Submit" value="上传">
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr></td>
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr></tr>
</wbr><wbr> </wbr><wbr> </wbr><wbr> </table>
</wbr><wbr> </wbr><wbr></form>
</wbr><wbr>利用JSP文件操作,记得一定要在头上写这两个语句:
<%@ page contentType="text/html;charset=gb2312" language="java" import="java.util.*" pageEncoding="gb2312"%>
<%request.setCharacterEncoding("gb2312"); %>
这是设置页面的编码格式。
</wbr><wbr>通过上面的页面,我们发现,form的表单地址是一个servlet,我的servlet如下所示:
</wbr><wbr> </wbr><wbr>public void doPost(HttpServletRequest request, HttpServletResponse response)
</wbr><wbr> </wbr><wbr> </wbr><wbr>throws ServletException, IOException {
</wbr><wbr> </wbr><wbr>ArrayList<String> others = new ArrayList<String>(); // 这是所有的表单元素的列表。</wbr>
<wbr> </wbr><wbr>String prefix = null; // 文件名
</wbr><wbr> </wbr><wbr>String t_ext = null; // 后缀
</wbr><wbr> </wbr><wbr>String fullname = null;
</wbr><wbr> </wbr><wbr>request.setCharacterEncoding("gb2312");
</wbr><wbr> </wbr><wbr>final long MAX_SIZE = 3 * 1024 * 1024;// 设置上传文件最大为 3M
</wbr><wbr> </wbr><wbr>// 允许上传的文件格式的列表
</wbr><wbr> </wbr><wbr>final String[] allowedExt = new String[] { "jpg", "jpeg", "gif", "txt",
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>"doc", "docx", "mp3", "wma", "m4a" };
</wbr><wbr> </wbr><wbr>response.setContentType("text/html;charset=gb2312");
</wbr><wbr> </wbr><wbr>// 设置字符编码为UTF-8, 这样支持汉字显示
</wbr><wbr> </wbr><wbr>response.setCharacterEncoding("gb2312");</wbr>
<wbr> </wbr><wbr>// 实例化一个硬盘文件工厂,用来配置上传组件ServletFileUpload
</wbr><wbr> </wbr><wbr>DiskFileItemFactory dfif = new DiskFileItemFactory();
</wbr><wbr> </wbr><wbr>dfif.setSizeThreshold(4096);// 设置上传文件时用于临时存放文件的内存大小,这里是4K.多于的部分将临时存在硬盘
</wbr><wbr> </wbr><wbr>dfif.setRepository(new File(request.getRealPath("/")
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>+ "ImagesUploadTemp"));// 设置存放临时文件的目录,web根目录下的ImagesUploadTemp目录</wbr>
<wbr> </wbr><wbr>// 用以上工厂实例化上传组件
</wbr><wbr> </wbr><wbr>ServletFileUpload sfu = new ServletFileUpload(dfif);
</wbr><wbr> </wbr><wbr>// 设置最大上传尺寸
</wbr><wbr> </wbr><wbr>sfu.setSizeMax(MAX_SIZE);</wbr>
<wbr> </wbr><wbr>PrintWriter out = response.getWriter();
</wbr><wbr> </wbr><wbr>// 从request得到 所有 上传域的列表
</wbr><wbr> </wbr><wbr>List fileList = null;
</wbr><wbr> </wbr><wbr>try {
</wbr><wbr> </wbr><wbr> </wbr><wbr>fileList = sfu.parseRequest(request);
</wbr><wbr> </wbr><wbr>} catch (FileUploadException e) {// 处理文件尺寸过大异常
</wbr><wbr> </wbr><wbr> </wbr><wbr>if (e instanceof SizeLimitExceededExcepti</wbr><wbr>on) {
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>out.println("文件尺寸超过规定大小:" + MAX_SIZE + "字节<p />");
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>out.println("<a href=\"upload.html\" target=\"_top\">返回</a>");
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>return;
</wbr><wbr> </wbr><wbr> </wbr><wbr>}
</wbr><wbr> </wbr><wbr> </wbr><wbr>e.printStackTrace();
</wbr><wbr> </wbr><wbr>}
</wbr><wbr> </wbr><wbr>// 没有文件上传
</wbr><wbr> </wbr><wbr>if (fileList == null || fileList.size() == 0) {
</wbr><wbr> </wbr><wbr> </wbr><wbr>out.println("请选择上传文件<p />");
</wbr><wbr> </wbr><wbr> </wbr><wbr>out.println("<a href=\"upload.html\" target=\"_top\">返回</a>");
</wbr><wbr> </wbr><wbr> </wbr><wbr>return;
</wbr><wbr> </wbr><wbr>}
</wbr><wbr> </wbr><wbr>// 得到所有上传的文件
</wbr><wbr> </wbr><wbr>Iterator fileItr = fileList.iterator();
</wbr><wbr> </wbr><wbr>// 循环处理所有文件
</wbr><wbr> </wbr><wbr>int i = fileList.size();
</wbr><wbr> </wbr><wbr>System.out.println(i);
</wbr><wbr> </wbr><wbr>String o[];//这是存放所有其它表单值的数组。
</wbr><wbr> </wbr><wbr>o = new String[i];
</wbr><wbr> </wbr><wbr>System.out.println("总共:" + i + "个字段");
</wbr><wbr> </wbr><wbr>int j = 0;
</wbr><wbr> </wbr><wbr>while (fileItr.hasNext()) {
</wbr><wbr> </wbr><wbr> </wbr><wbr>FileItem fileItem = null;
</wbr><wbr> </wbr><wbr> </wbr><wbr>String path = null;
</wbr><wbr> </wbr><wbr> </wbr><wbr>long size = 0;
</wbr><wbr> </wbr><wbr> </wbr><wbr>// 得到当前文件
</wbr><wbr> </wbr><wbr> </wbr><wbr>fileItem = (FileItem) fileItr.next();
</wbr><wbr> </wbr><wbr> </wbr><wbr>// 忽略简单form字段而不是上传域的文件域(<input type="text" />等)
</wbr><wbr> </wbr><wbr> </wbr><wbr>if (fileItem == null || fileItem.isFormField()) {</wbr>
<wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>String name = fileItem.getFieldName();
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>// if (name.equals("name")) {
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>String namea = fileItem.getString("gb2312");
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>String a = new String(namea.getBytes(), "gb2312");
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>o[j] = a;
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>System.out.println(o[j]);
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>// }
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>j++;
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>continue;
</wbr><wbr> </wbr><wbr> </wbr><wbr>}
</wbr><wbr> </wbr><wbr> </wbr><wbr>System.out.println(j);</wbr>
<wbr> </wbr><wbr> </wbr><wbr>// 得到文件的完整路径
</wbr><wbr> </wbr><wbr> </wbr><wbr>path = fileItem.getName();
</wbr><wbr> </wbr><wbr> </wbr><wbr>// 得到文件的大小
</wbr><wbr> </wbr><wbr> </wbr><wbr>size = fileItem.getSize();
</wbr><wbr> </wbr><wbr> </wbr><wbr>if ("".equals(path) || size == 0) {
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>out.println("请选择上传文件<p />");
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>out.println("<a href=\"upload.html\" target=\"_top\">返回</a>");
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>return;
</wbr><wbr> </wbr><wbr> </wbr><wbr>}</wbr>
<wbr> </wbr><wbr> </wbr><wbr>// 得到去除路径的文件名
</wbr><wbr> </wbr><wbr> </wbr><wbr>String t_name = path.substring(path.lastIndexOf("\\") + 1);
</wbr><wbr> </wbr><wbr> </wbr><wbr>// 得到文件的扩展名(无扩展名时将得到全名)
</wbr><wbr> </wbr><wbr> </wbr><wbr>t_ext = t_name.substring(t_name.lastIndexOf(".") + 1);
</wbr><wbr> </wbr><wbr> </wbr><wbr>// 拒绝接受规定文件格式之外的文件类型
</wbr><wbr> </wbr><wbr> </wbr><wbr>int allowFlag = 0;
</wbr><wbr> </wbr><wbr> </wbr><wbr>int allowedExtCount = allowedExt.length;
</wbr><wbr> </wbr><wbr> </wbr><wbr>for (; allowFlag < allowedExtCount; allowFlag++) {
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>if (allowedExt[allowFlag].equals(t_ext))
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>break;
</wbr><wbr> </wbr><wbr> </wbr><wbr>}
</wbr><wbr> </wbr><wbr> </wbr><wbr>if (allowFlag == allowedExtCount) {
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>out.println("请上传以下类型的文件<p />");
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>for (allowFlag = 0; allowFlag < allowedExtCount; allowFlag++)
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>out.println("*." + allowedExt[allowFlag]
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>+ " ");
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>out
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>.println("<p /><a href=\"upload.html\" target=\"_top\">返回</a>");
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>return;
</wbr><wbr> </wbr><wbr> </wbr><wbr>}</wbr>
<wbr> </wbr><wbr> </wbr><wbr>long now = System.currentTimeMillis();
</wbr><wbr> </wbr><wbr> </wbr><wbr>// 根据系统时间生成上传后保存的文件名
</wbr><wbr> </wbr><wbr> </wbr><wbr>prefix = String.valueOf(now);
</wbr><wbr> </wbr><wbr> </wbr><wbr>// 保存的最终文件完整路径,保存在web根目录下的ImagesUploaded目录下
</wbr><wbr> </wbr><wbr> </wbr><wbr>String u_name = request.getRealPath("/") + "upload/" + prefix + "."
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>+ t_ext;
</wbr><wbr> </wbr><wbr> </wbr><wbr>try {
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>// 保存文件
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>fileItem.write(new File(u_name));
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>System.out.println(prefix + "." + t_ext);
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>out.println("文件上传成功. 已保存为: " + prefix + "." + t_ext
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>+ " 文件大小: " + size + "字节<p />");
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>out.println("<a href=\"upload.html\" target=\"_top\">继续上传</a>");
</wbr><wbr> </wbr><wbr> </wbr><wbr>} catch (Exception e) {
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>e.printStackTrace();
</wbr><wbr> </wbr><wbr> </wbr><wbr>}
</wbr><wbr> </wbr><wbr>}
</wbr><wbr> </wbr><wbr>fullname = "upload/" + prefix + "." + t_ext;
</wbr><wbr> </wbr><wbr>System.out.println(fullname);</wbr>
<wbr> </wbr><wbr>String sql =””;
</wbr><wbr> </wbr><wbr>System.out.println(sql);
</wbr><wbr> </wbr><wbr>CarDAO dao = new CarDAO();//这里是操作数据库的代码。</wbr>
<wbr> </wbr><wbr>if(dao.addCar(sql)){
</wbr><wbr> </wbr><wbr> </wbr><wbr> </wbr><wbr>out.println("添加用户成功!!"); </wbr><wbr> </wbr><wbr>
</wbr><wbr> </wbr><wbr>}else{
</wbr><wbr> </wbr><wbr> </wbr><wbr>out.println("添加用户失败!!!");
</wbr><wbr> </wbr><wbr>}
</wbr><wbr> </wbr><wbr>
</wbr><wbr>}</wbr>
这时,我们就可以在上传文件的同时,将文件的路径信息及其它表单信息存入到数据库中,
另外在web.xml中, 添加如下代码:
<wbr><servlet>
</wbr><wbr> </wbr><wbr><servlet-name>FileUploadServlet</servlet-name>
</wbr><wbr> </wbr><wbr><servlet-class>servlet.FileUploadServlet</servlet-class>
</wbr><wbr></servlet></wbr>
<wbr><servlet-mapping>
</wbr><wbr> </wbr><wbr><servlet-name>FileUploadServlet</servlet-name>
</wbr><wbr> </wbr><wbr><url-pattern>/FileUploadServlet</url-pattern>
</wbr><wbr></servlet-mapping>
这时,就可以完成操作了、
本例在Tomcat 6.0 和Resin3.0.25 下边测试成功。本人第一次写,有不对的地请大家指教。</wbr>
发表评论
-
【小程序】java生成integer的字符串序列
2016-08-06 11:33 4671、效果如下: 输入1——5,返回1,2,3, ... -
Java单线程池
2015-07-22 10:04 605package com.hebei.read.core.pl ... -
自定义Java多线程池
2015-07-22 10:04 554package com.anda.threads; i ... -
自定义Java线程池
2015-07-22 10:02 0package com.anda.threads; i ... -
Linux下将Tomcat设置为Chkconfig启动方式
2013-12-14 16:19 730#!/bin/sh # # tomcat: Start ... -
java文件下载文件名乱码(转)
2013-11-19 11:25 738response.setHeader(...)下载 ... -
Tomcat、Apache、Mod_JK整合
2012-01-16 19:17 1547Apache、Tomcat、mod_jk 域名解析 1、安装 ... -
Java HashMap的两种排序方式
2011-12-09 18:31 942Map<String, Integer> ... -
使网页变灰,支持IE、FireFox、Opera、360浏览器等
2011-12-06 10:44 28901、对IE的支持,只需要在CSS中添加如下代码: ... -
Java 获取指定时间
2011-12-05 17:29 2138// 用来全局控制 上一周,本周,下一周的周数变化 ... -
Java 获取系统信息,包括CPU使用率、硬盘大小、网卡状态、系统信息等
2011-10-28 15:05 8827采用singar.jar实现,需要将sigar-x86-win ... -
CentOS Linux 下Tomcat启动脚本
2011-09-24 10:09 1586#!/bin/bash # # Init file ... -
IE6下DIV高度的问题
2011-06-30 09:14 869在IE6下,使用 height:10px;时,比实际的高度要高 ... -
非常不错的JS插件
2010-04-22 10:26 676从网上发现一个JS日期插件,经过自己修改,非常好用了,在此标识 ... -
基于xfire的web service搭建
2009-03-27 12:39 1656这里,用的xfire1.2.6和Spring 2.0,开发工具 ... -
Linux系统下JSP服务器配置步骤详解
2008-03-07 10:27 996接触JSP服务器 的人基本上都是从JSP的安装开始的 ... -
Java专业术语标准化规范
2008-03-08 09:32 880-A- AJAX: (建议不译,原因:专有名词) ... -
Eclipse开发经典教程:SWT布局(1)
2008-03-08 09:52 2428在Java 中,GUI程序开发的目标之一是跨平台,而每种类型 ... -
Eclipse开发经典教程:SWT布局(2)
2008-03-08 09:54 2600GridLayout布局 GridLayout ... -
JSP 文件上传
2008-08-18 17:22 1113这些天做JSP 的网站,遇到一个上传文件的问题,经过查找,终 ...
相关推荐
Apache Commons FileUpload和Commons IO两个库是Java中处理文件上传的关键组件,它们为SpringMVC和MyBatis这样的框架提供了强大的支持。本篇文章将深入探讨这两个库以及它们在图片处理中的作用。 首先,`commons-...
通过以上步骤,我们就使用Apache Commons FileUpload组件实现了一个基本的文件上传功能。你可以根据自己的需求对这个示例进行扩展,比如添加错误处理、文件类型检查和存储优化等。参考提供的博文链接,可以获取更多...
### Commons-FileUpload 实现文件上传下载 #### 知识点概述 Commons-FileUpload 是 Apache 提供的一个用于处理 HTTP 文件上传的组件。它基于 Servlet 规范,并且能够解析来自 `multipart/form-data` 编码类型的 ...
在本文中,我们将深入探讨如何使用Apache Commons FileUpload组件来实现文件上传功能。Apache Commons FileUpload是一个用于处理HTTP请求中的多部分数据的Java库,它使得在Servlet或JSP应用中处理文件上传变得简单易...
本教程将详细介绍如何利用commons-fileupload实现文件上传功能,并提供一个简单的实例。 **一、Apache Commons FileUpload简介** Apache Commons FileUpload是Apache软件基金会开发的一个开源组件,专门处理HTTP...
在开发Java应用程序,尤其是涉及到Web应用中的文件上传功能时,`commons-fileupload.jar`和`commons-io.jar`是两个至关重要的库。这两个JAR文件分别提供了Apache Commons FileUpload和Apache Commons IO项目的功能,...
例如,开发者可以先使用FileUpload解析出上传的文件,然后利用Commons IO将其保存到服务器的指定位置。 这两个库的源代码文件(sources)也一同提供,这对于学习和理解其内部实现机制非常有帮助。通过阅读源码,...
`commons-fileupload-1.2.1.jar`是Apache Commons FileUpload组件的特定版本,这是一个用于处理HTTP请求中的多部分表单数据的库。在Web表单中,当用户选择要上传的文件时,浏览器会将数据以多部分/形式编码的方式...
`commons-fileupload`组件是Apache Commons项目中的一个子项目,主要负责处理HTTP协议下的文件上传功能。在Web应用中,用户可能需要上传图片、文档等文件,这时`commons-fileupload`就发挥了重要作用。本篇文章将...
本文将深入探讨如何使用Commons FileUpload组件来处理文件上传。 Apache Commons FileUpload是Apache Commons项目的一部分,专门设计用于处理HTTP请求中的多部分数据,即通常在HTML表单中用于文件上传的数据格式。...
总的来说,`commons-fileupload`组件是Java Web开发中不可或缺的一部分,它极大地简化了文件上传的实现,让开发者可以专注于业务逻辑,而不是底层的细节。通过结合`commons-fileupload`和`commons-io`,我们可以构建...
在Java Web开发中,文件上传是一项常见的功能,Apache Commons FileUpload和Smart Upload是两个常用的文件上传组件。这里我们将深入探讨这两个库以及如何在实际项目中使用它们。 首先,Apache Commons FileUpload是...
以上就是关于Struts2中利用Apache Commons FileUpload和Apache Commons IO进行文件上传和下载的基本原理和实现流程。这两个库大大简化了处理文件操作的复杂性,提高了代码的可读性和可维护性。在实际开发中,应根据...
在Java开发中,上传文件是一项常见的任务,而`commons-fileupload-1.3.jar`和`commons-io-2.4.jar`这两个jar包是Apache Commons项目中的重要组件,专门用于处理文件上传操作。Apache Commons是Java社区的一个子项目...
《Java文件上传:深入解析Apache Commons FileUpload 1.3.3》 在Java开发中,文件上传功能是一项常见的需求,而Apache Commons FileUpload库则是处理这种需求的强大工具。本篇将详细介绍Apache Commons FileUpload ...
《Apache Commons FileUpload组件详解与应用实践》 Apache Commons FileUpload是Java环境下处理HTTP请求中文件上传的一个强大工具,尤其在Web开发中,文件上传功能是必不可少的一部分。本篇文章将详细解析`commons-...
标题中的"commons-fileupload"和"io-1.3.2.rar"以及描述和标签中的相同信息,都指向了Apache Commons项目中的两个关键组件:Apache Commons FileUpload和Apache Commons IO。这两个库是Java开发中处理文件上传和I/O...
这两个组件在Java开发中扮演着重要的角色,尤其在处理Web应用程序中的文件上传功能时。 Apache Commons FileUpload是Apache软件基金会提供的一个开源库,专门用于处理HTTP协议中的多部分/表单数据,也就是我们通常...
基于HTTP传输协议的Web网页中,采用嵌入Commonsfileupload组件的Struts2框架,实现了文件的上传与下载.利用OGNL表达式提取Session持久层中的文件名,并利用此文件名实现下载文件的动态更名.灵活利用struts2.0自身...