文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>上传类[已验证]

上传类[已验证]

时间:2007-08-21  来源:sdwsyjp

/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package edu.sdau.struts.action;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
import edu.sdau.struts.form.Stu_uploadForm; /**
 * MyEclipse Struts Creation date: 08-21-2007
 *
 * XDoclet definition:
 *
 * @struts.action path="/stu_upload" name="stu_uploadForm"
 *                input="/stu_upload.jsp" scope="request" validate="true"
 */
public class Stu_uploadAction extends Action {
 /*
  * Generated Methods
  */
 /**
  * Method execute
  *
  * @param mapping
  * @param form
  * @param request
  * @param response
  * @return ActionForward
  */
 public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response) {
  Stu_uploadForm stu_uploadForm = (Stu_uploadForm) form;// TODO
                // Auto-generated
                // method stub
  String teacher = stu_uploadForm.getTeacher();
  String document = stu_uploadForm.getDocument();
  String department = stu_uploadForm.getDepartment();
  String major = stu_uploadForm.getMajor();
  String stuclass = stu_uploadForm.getStuclass();
  String fileName = null ;
  FormFile upFile = stu_uploadForm.getFile1();
  fileName = upFile.getFileName();
  String path = request.getRealPath("/upFiles");
  path=path + "\\" + teacher + "\\" + document + "\\"
   + "\\" + department + "\\" + major +"\\" + stuclass;
  File file =new File(path);
  if(!file.exists())
  {
   file.mkdirs();
  }
  
  try {
   InputStream fin = upFile.getInputStream();
   OutputStream fout = new FileOutputStream(path + "\\" +fileName);
   byte[] buffer = new byte[8192];
   int readByte = 0;
   while((readByte = fin.read(buffer, 0, 8192))>0)
    {
    fout.write(buffer, 0, readByte);
    }
   fin.close();
   fout.close();
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  
  return null;
 }
}
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载