tomcat服务器里的照片怎么把它保存到硬盘里??
求大神解释啊。急求急求!!!!!!
------解决方案--------------------
自己学一下吧http://blog.sina.com.cn/s/blog_60afee6e010136dc.html
------解决方案--------------------protected Map<String, Object> parseMultipart(HttpServletRequest request) {
Map<String, Object> map = new HashMap<String, Object>();
RequestContext ctx = new ServletRequestContext((HttpServletRequest) request);
if (!FileUpload.isMultipartContent(ctx))
return map;
try {
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setSizeMax(1024 * 1024 * 5);// 设置文件限制为5M
List<FileItem> items = upload.parseRequest((HttpServletRequest) request);
if (items != null) {
Map<String, List<Object>> tmp = new HashMap<String, List<Object>>();
for (FileItem item : items) {
Object value = item.isFormField() ? item.getString("UTF-8") : item;
if (!tmp.containsKey(item.getFieldName())) {
List<Object> values = new ArrayList<Object>();
tmp.put(item.getFieldName(), values);
}
tmp.get(item.getFieldName()).add(value);
}
if (tmp.size() > 0) {
for (String key : tmp.keySet()) {
List<Object> values = tmp.get(key);
if (values.size() == 1) {
map.put(key, values.get(0));
} else {
map.put(key, values.toArray());
}
}
}
}
} catch (Exception e) {
logger.error(e);
}
return map;
}
------解决方案--------------------public void fileUpload2() {
String result = "OK";
// upload.setSizeMax(1024 * 1024 * 5);
HttpServletRequest request = ServletActionContext
.getRequest();
String appName = request.getContextPath();
// 上传文件夹路径
String path = "../webapps" + appName + "/files/";
// 返回上传图片的网络地址
String basePath = request.getScheme() + "://" + request.getServerName()
+ ":" + request.getServerPort() + appName + "/" + "files/";
String httpurl="";
try {
String fname =this.getFileStream2FileName();
//System.out.println(fname);
//