寻找用jsp结合commons-fileupload上传图片的例子程序,搞定马上结贴.
commons-fileupload-1.1.1.jar
commons-io-1.2.jar
这两个文件已放在\WEB-INF\lib下,
现建了两个文件
1>new.jsp
<form action= "save.jsp " enctype= "multipart/form-data " method= "POST ">
enter your name: <input type= "text " name= "name "> <br/>
select the file: <input type= "file " name= "file "> <br/>
<input type= "submit " value= "submit ">
</form>
2>save.jsp
<%@ page language= "java " contentType= "text/html; charset=utf-8 "
pageEncoding= "utf-8 "%>
<%@ page import= "java.util.List "%>
<%@ page import= "java.util.Iterator "%>
<%@ page import= "java.io.File "%>
<%@ page import= "org.apache.commons.fileupload.DiskFileUpload "%>
<%@ page import= "org.apache.commons.fileupload.FileItem "%>
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=ISO-8859-1 ">
<title> Insert title here </title>
</head>
<body>
<%
DiskFileUpload fu = new DiskFileUpload();
fu.setSizeThreshold(4096);
fu.setSizeMax(1000000);
fu.setRepositoryPath( "D:\\ ");
List fileItems = fu.parseRequest(request);
Iterator itr = fileItems.iterator();
while(itr.hasNext()) {
FileItem fi = (FileItem)itr.next();
File fNew= new File(application.getRealPath( "/ "), fi.getName());
fi.write(fNew);
}
%>
</body>
</html>
===
结果提示错误,
谁有这方面的例子,能不能发一个给我,
OK后,马上结贴.谢谢
------解决方案--------------------放到lib下后引入了没有?