如果你描述的没有问题的话,应该是fileupload组件自身的问题
但是建议你做这样的修改
while (ite.hasNext())
==>
while (ite != null && ite.hasNext())
在使用一个变量之前判断一下是不是有效
但是建议你做这样的修改
while (ite.hasNext())
==>
while (ite != null && ite.hasNext())
在使用一个变量之前判断一下是不是有效
解决方案 »
- 谁有jax-ws的教程啊!!
- ejb怎样连接数据库
- java版本的搜索引擎demo,大家帮我找下,有好的demo推荐下,我周三就要交了,我对这块是很陌生啊!
- weblogic JMS 客户端如何判断server已关闭或网络已断开?(尝试jmsconnection.setExceptionListener未果)
- 快烦死了,hibernate No Dialect mapping for JDBC type: -1 错误
- JSP+Spring遇到麻烦
- Struts+Spring的AOP问题
- 要查看Struts例子如何设置呢?
- 怎么根据不同的部门显示相对应的员工?SQL语句要怎么写呢?J2EE,采用MVC架构
- UML里用例图(User Case)和类图(Class)的关系
- 求软件 J2SE SDK1.4和 J2EE SDK 1.4
- java实现Slowly Changing Dimension
throws ServletException, IOException { String uploadpath = "F:\\temp";
File temppath = new File("../tmp");
request.setCharacterEncoding("gb2312"); response.setContentType("text/html;charset=gb2312");
PrintWriter out = response.getWriter(); DiskFileItemFactory factory = new DiskFileItemFactory();
factory.setSizeThreshold(4096 * 1024);
factory.setRepository(temppath);
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEncoding("gb2312"); try {
List <FileItem> items = upload.parseRequest(request);
Iterator ite = items.iterator();
while (ite.hasNext()) { FileItem item = (FileItem) ite.next();
if(!item.isFormField()) //查看是否是file表单的内容
out.print(item.getFieldName()); String filename = item.getName();
filename = filename.substring(filename.lastIndexOf("\\") + 1);
File file = new File(uploadpath, filename);
out.print(filename);
//item.write(file);
}
} } catch (FileUploadException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }