struts2上传文件 谁有完整地struts2上传文件代码,要详细地,要存到硬盘上的,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public String addUser() { // 取得服务器上上传文件存放的路径 String str = ServletActionContext.getServletContext().getRealPath( "/files/"); // 获得上传文件的完整路径 String FilePath = str + File.separator + fileFileName; InputStream is = null; OutputStream os = null; try { is = new FileInputStream(file); os = new FileOutputStream(FilePath); byte[] b = new byte[1024]; int len = 0; while ((len = is.read(b)) != -1) { os.write(b, 0, len); os.flush(); } is.close(); os.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } ss.addObject(user); return "ha"; } 其实很简单的action中申明一个文件对象然后其他操作文件方式和平时操作文件方式相同即可 高分求救??war文件上传到服务器的问题?? eclipse 使用URL连接出错,求解 写研发课长晋升简报-学习与工作计划,请赐予建议 tomcat问题 怎样提交问题 文件下载的问题 帮我看下这个方法是怎么调用的 时间比较问题 搭车去了~~~结束这痛苦的出差。。。今天一天好像还没吃饭。。。 Java web在MVC模式下,怎样设计作为控制器的Controller才能使得它不那么臃肿庞大? 关于开源软件协议的几个问题 if(rs.next())报错
public String addUser() {
// 取得服务器上上传文件存放的路径
String str = ServletActionContext.getServletContext().getRealPath(
"/files/");
// 获得上传文件的完整路径
String FilePath = str + File.separator + fileFileName;
InputStream is = null;
OutputStream os = null;
try {
is = new FileInputStream(file);
os = new FileOutputStream(FilePath);
byte[] b = new byte[1024];
int len = 0;
while ((len = is.read(b)) != -1) {
os.write(b, 0, len);
os.flush();
}
is.close();
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
ss.addObject(user);
return "ha";
}
action中申明一个文件对象
然后其他操作文件方式和平时操作文件方式相同即可