当前位置:首页 » 文件管理 » struts2文件上传进度条

struts2文件上传进度条

发布时间: 2022-06-02 06:39:25

① 关于struts2框架的文件上传问题。。。上传的文件超过2MB就报下面的异常,请问怎么解决

在struts.xml中设置
<constant name="struts.multipart.maxSize" value="314572800"></constant> <!-- 允许300M -->
可以允许上传300M的呢!我试了下,上传了个202M的电影,竟然上传成功了!

② struts2+jquery如何实现点击“上传”按钮,实现从本机选择图片,然后自动上传,类似于上传证件的那种

Uploadify是JQuery的一个上传插件,实现的效果非常不错,带进度显示。LZ可以参考下。希望能帮到你!

③ 100分。struts2实现的图片上传 例子

这个就是struts2的,我艹
-------------已在linux服务上线---------------------
private File userfile;
private String userfileContentType;
private String userfileFileName;
//get set 略
public void uploadImg() throws Exception {
Person person = factory.getUserServiceImpl().getCurrentPerson();//得到当前用户
HttpServletResponse response = ServletActionContext.getResponse();
HttpServletRequest request = ServletActionContext.getRequest();
Calendar cal = Calendar.getInstance();
int yy = cal.get(Calendar.YEAR);
String savePath = request.getSession().getServletContext().getRealPath("/")+"/upload/images/"+yy+"/";
String filePath = savePath ;
File dir = new File(filePath);
if (!dir.exists()) {
dir.mkdirs();
}
String fileName = userfileFileName;
String basePath = "upload/images/"+yy+"/";
String uuid = UUID.randomUUID().toString();
String fileType=fileName.substring(fileName.length()-3);
File uploadedFile = new File(filePath + uuid+"."+fileType);
//userfile.write(uploadedFile);
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream(userfile), 1024*1024*10);
out = new BufferedOutputStream(new FileOutputStream(uploadedFile),
1024*1024*10);
byte[] buffer = new byte[1024*1024*10];
int len = 0;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != in) {
try {
in.close();
} catch (IOException e) {
}
}
if (null != out) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

response.setContentType("text/html;charaset=utf-8");
response.getWriter().write("{success:'true',fileURL:'"+basePath + uuid+"."+fileType + "'}");
}

④ jquery 进度条 struts2

请按照标准的W3C书写

⑤ struts2中在action中怎么对文件上传进行处理

InputStream is = null;
OutputStream ops = null;
for (int i = 0; i < file.size(); i++) {
try {
TFile tfile = new TFile();
if (file.get(i) == null) {
continue;
}
is = new FileInputStream(file.get(i));
//路径
String root = ServletActionContext.getRequest()
.getRealPath("/uploads");
// 根据系统时间取名字
int pos = this.getFileFileName().get(i).lastIndexOf(".");
String ext = this.getFileFileName().get(i).substring(pos);
// 获得系统时间,产生文件名
long now = System.currentTimeMillis();
String nowtime = String.valueOf(now);
File destFile = new File(root + "/", nowtime + ext);
ops = new FileOutputStream(destFile);
byte[] b = new byte[400];
int length = 0;
while ((length = is.read(b)) > 0) {
ops.write(b, 0, length);
// ops.write(b); 这样子同样可行
}
tfile.setFileName(getFileFileName().get(i));
tfile.setFilePath("/uploads/" + nowtime + ext);
tfile.setFileCreatetime(currentDate);
tfile.setFileDataid(uptdt.getDataId());
fileservice.saveFile(tfile);// 保存上传文件信息
} catch (Exception ex) {
ex.printStackTrace();

} finally {
is.close();
ops.close();
}
}

⑥ Struts2进行文件的上传下载,上传已经成功了,但是文件下载时出现了问题,下载的文件是action代码。

${downloadFileName}

要和action中的属性相同

⑦ 求一java进度条的实现,struts2的,最好是能拿来马上用的,谢了

明确的告诉你,没有,WEB程序是无状态连接的,不能获取的进度,现在看到的那些进度条都是通用JS写的。

⑧ struts2 如何实现上传整个文件夹的功能

一、压缩文件其实是可以0压缩率直接打包,这样其实蛮快的
二、看到网上说Applet可以上传文件夹,具体远离不清楚,你可以看看
三、最笨的方法,用Ajax做一个递归遍历文件夹的函数,如果是文件就上传上去,如果是文件夹就请求后台新建文件夹
四、用JSON格式把目录和文件封装起来,统一传到后台,但是后台处理要比较麻烦

⑨ struts2中文件上传问题

你要学会用debug模式来调试自己的代码。把断点设置在 String root = ServletActionContext.getRequest().getRealPath("/upload"); 可以一步步查看每个变量和属性的值 ,这样更容易找到问题。
这里你需要查看root 和 destfile的值 这样很容易看出你得到的路径是否为你想要设置的路劲。
也可以用system.out.println(root) 打印到控制台看一下。

热点内容
vpn韩国服务器地址 发布:2025-03-20 07:12:44 浏览:25
打码软件源码 发布:2025-03-20 07:08:06 浏览:109
前端android 发布:2025-03-20 06:50:42 浏览:93
进制转换栈c语言 发布:2025-03-20 06:50:31 浏览:339
myeclipse不自动编译了 发布:2025-03-20 06:41:38 浏览:777
led汽车大灯和卤素灯该选哪个配置 发布:2025-03-20 06:40:55 浏览:917
sql网校 发布:2025-03-20 06:16:42 浏览:279
安卓手机图标排列为什么会混乱 发布:2025-03-20 06:16:05 浏览:761
手机pin初始密码是多少 发布:2025-03-20 06:15:59 浏览:900
javaif常量变量 发布:2025-03-20 06:15:57 浏览:344