百分请教个common-fileupload的问题

xmadan 2006-07-27 05:02:45
使用fileupload
已导入包commons-fileupload-1.1.1.jar、commons-io-1.2.jar
结果读不到页面的file类型,请各位大侠帮忙,代码如下所示
代码一跑到就
while (iter.hasNext()) {
就跳出while
form的类型也有设
估计是包的问题,代码我从另一个项目来的,只改了点,另一个项目的可以
...全文
228 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xmadan 2006-08-02
  • 打赏
  • 举报
回复
分随便给了吧
xmadan 2006-08-02
  • 打赏
  • 举报
回复
问题已经自己解决了,action不引用form就没事了。
terry_yip 2006-07-31
  • 打赏
  • 举报
回复
你在while之前的代码都没错。错应该是页面上的问题,你的form和file为什么不用struts的标签呢?
xmadan 2006-07-31
  • 打赏
  • 举报
回复
没有人能解决吗?
ray_1981 2006-07-27
  • 打赏
  • 举报
回复
关注中!
mrdangdong 2006-07-27
  • 打赏
  • 举报
回复
关注,关注
xmadan 2006-07-27
  • 打赏
  • 举报
回复
action(略去部分):
public class ImportEdiAction
extends ActionTemplate {
public ActionForward importEdi(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws
Exception {
try {
String path = CommonUtil.UPLOAD_PATH;
DiskFileUpload upload = new DiskFileUpload();
upload.setRepositoryPath(path);
List list = upload.parseRequest(request);
Iterator iter = list.iterator();
while (iter.hasNext()) {
FileItem file = (FileItem) iter.next();
if (file != null) {
// 写入文件a.txt,你也可以从fileName中提取文件名:
String fileName = "upload"
+ String.valueOf(new Date().getTime()) +
".txt";
file.write(new File(path + fileName));
//读取并保存到数据库中
ImportService ser = ((ImportService)getService());
List result = ser.importEdi(path + fileName,imAllFlag);
if(result.size() != 0){
//审核不通过
request.setAttribute("import.error",result);
}
//删除临时文件
file.delete();
}
}
}catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward(this.IMPORT_PAGE);
}
}
xmadan 2006-07-27
  • 打赏
  • 举报
回复
jsp如下所示(略去部分无关紧要的代码):
<%@ page contentType="text/html; charset=GB2312"
import="java.util.List,java.util.Iterator" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@include file="commonHead.jsp" %>
<body >
<form name="f1" action="importEdiAction.do?method=importEdi" method="POST" enctype="multipart/form-data">
<table width="98%">
<tr>
<td>导入文件</td>
<td><input type="file" name="txtFile" value=""/></td>
</tr>
<tr>
<td colspan="2">
  <input name="btnImport" type="button" value="导入" class="formButton00" onclick="doImport()"

style="${importEdiMaintain}"/>
</td>
</tr>
</table>
<input type="hidden" name="txtHiddenFile" value="">
</form>
</body>
</html>

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧