在这里用到了java 的一个开源jar 包:叫做upload 是用来做上传用的。在struts中使用:
在下面就一个实例来说明这个jar包的用法。
说到上上传第一肯定要有一个上传点。我用了一个struts的一个
<html:file property="files"/>
获得一个文件的路。
第二部就是用一个Action得到文件路径。并进行上传:代码如下:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UploadForm uploadForm = (UploadForm) form;// TODO Auto-generated method stub
FormFile formFile = uploadForm.getFiles();
try {
InputStream input = formFile.getInputStream();
String rootpath = request.getSession().getServletContext().getRealPath("/upload");
OutputStream out = new FileOutputStream(rootpath+"/"+formFile.getFileName());
byte[] buffer = new byte[1024];
while(input.available()>1024){
input.read(buffer);
out.write(buffer);
}
buffer = new byte[input.available()];
input.read(buffer);
out.write(buffer);
out.close();
input.close();
} catch (IOException e) {
e.printStackTrace();
return mapping.findForward("fail");
}
return mapping.findForward("success");
}
其中特红部分代表目标地址:全路径:
上面的路径是:
D:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\strutsupload\upload\
下面有一实例。可参考:

被折叠的 条评论
为什么被折叠?



