action

package com.my.other;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.DiskFileUpload;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUpload;
import org.apache.commons.fileupload.ProgressListener;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class UploadAction extends Action {

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("UTF-8");

UploadProgressListener pl = new UploadProgressListener(request);

long start_time = System.currentTimeMillis();

DiskFileUpload fu = new DiskFileUpload();
fu.setProgressListener(pl);
List items = fu.parseRequest(request);
System.out.println(items.size());
int flag = 0;
for (int i = 0; i < items.size(); i++) {
FileItem fi = (FileItem)items.get(i);
if (!fi.isFormField() && fi.getName().trim().equals("")) {
flag = 1;
}
}
if(flag == 1) {
response.getWriter().print("<root><message>上传失败</message></root>");
//throw new Exception("sfsdf");
}else{
System.out.println("sdfds");
for (int i = 0; i < items.size(); i++) {
FileItem fi = (FileItem)items.get(i);
if (fi.isFormField()) {
} else {
if ("".equals(fi.getName().trim())) {
continue;
}

//ȡ�ļ�����
String filename = fi.getName();
int pos = filename.lastIndexOf("\\");
filename = filename.substring(pos + 1);

fi.write(new File(this.getServlet().getServletContext().getRealPath("//")
+ "//files//" + filename));
}
}

long end_time = System.currentTimeMillis();
System.out.println("Used time:" + (end_time - start_time ) );
response.getWriter().print("<root><message>上传成功</message></root>");
}
response.flushBuffer();
return null;
}

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器学习模型机器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值