我在做一个上传文件和图片的程序,使用的是ssh。
需求:上传文件要支持大部分文件类型。
上传图片要求可以上传所有图片类型和flash。如果jspsmart*这个能上满足要求,最好用这个组件。之前我在网上找了一些代码,由于我水平有限,怎么改都不能正常上传。谢谢!
需求:上传文件要支持大部分文件类型。
上传图片要求可以上传所有图片类型和flash。如果jspsmart*这个能上满足要求,最好用这个组件。之前我在网上找了一些代码,由于我水平有限,怎么改都不能正常上传。谢谢!
解决方案 »
- 在用户登录系统之后,进行执行logout的操作时候出现异常,找不到session
- hibernate+struts2+spring项目连接网络运行项目没问题,但断开网络时报错
- 关于struts2中的namespace
- spring+hibernate+struts2 相关
- spring Acegi 能否获得所有登陆用户信息
- Hibernate operation: Cannot open connection错误求助
- 如何将jb2006自带的axis1.2升级为axis2 1.3?
- 救命啊``Windows2003的DirectX``
- 请问关于WebLogic7.0的内存管理/内存泄露?
- js里 document.forms[0].action="app/AppoRemo.action"啥意思啊
- =======hibernate 添加默認值問題=======
- jsp页面中如何防止并发啊
MultiPartRequestWrapper multiWrapper = (MultiPartRequestWrapper) request;
String path = ServletActionContext.getServletContext().getRealPath("/"); String filepath = path + "temp/"; Enumeration fileParameterNames = multiWrapper.getFileParameterNames();
while (fileParameterNames != null && fileParameterNames.hasMoreElements()) {
// get the value of this input tag
String inputName = (String) fileParameterNames.nextElement(); // get the content type
String[] contentType = multiWrapper.getContentTypes(inputName); if (isNonEmpty(contentType)) {
// get the name of the file from the input tag
String[] fileName = multiWrapper.getFileNames(inputName); if (isNonEmpty(fileName)) {
filepath += fileName[0];
// get a File object for the uploaded File
File[] files = multiWrapper.getFiles(inputName);
try {
BufferedInputStream in = new BufferedInputStream(new FileInputStream(files[0]));//获得文件输入流
FileOutputStream a = new FileOutputStream(new File(filepath));
BufferedOutputStream output = new BufferedOutputStream(a);
byte[] buff = new byte[2048];
int bytesRead; while (-1 != (bytesRead = in.read(buff, 0, buff.length))) {
output.write(buff, 0, bytesRead);
}
output.flush();
output.close();
in.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
文件上传无非就是获得上传的文件对象转换为流,再写入服务器你指定的目录,仅些而已