import java.io.File;
import java.lang.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
inputtypefile不上传文件import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lotus.domino.Database;
import lotus.domino.Document;
import lotus.domino.EmbeddedObject;
import lotus.domino.NotesException;
import lotus.domino.NotesFactory;
import lotus.domino.NotesThread;
import lotus.domino.RichTextItem;
import lotus.domino.Session;
import org.apachemons.fileupload.FileItem;
import org.apachemons.fileupload.disk.DiskFileItemFactory;
import org.apachemons.fileupload.servlet.ServletFileUpload;
import java.lang.Math;
public class FileUpLoads extends HttpServlet {
// 要上传文件的文档的id
private String unid;
// 要上传文件的文档的divid;
private String divid;
// 保存文件的服务器名
private String svrname;
// 保存文件的数据库名
private String dbname;
// 保存文件的数据库表单名
private String formname;
// 保存文件名的域名
private String filename;
// 保存文件大小的域名
private String filesize;
// 保存临时文件的路径
private String path;
private Session ss;
private Database db;
private Document doc;
private RichTextItem rtitem;
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
  super.destroy(); // Just puts "destroy" string in 0log
  // Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request
*            the request send by the client to the server
* @param response
*            the response send by the server to the client
* @throws ServletException
*            if an error occurred
* @throws IOException
*            if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
     
  this.doPost(request, response);
}
// 上传附件doPost():
public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
  response.setContentType("text/html");
  PrintWriter out = Writer();
  try {
  DiskFileItemFactory factory = new DiskFileItemFactory();
  ServletFileUpload file = new ServletFileUpload(factory);
  file.setSizeMax(-1);
  file.setFileSizeMax(-1);
  File realFile = null;
  try {
    // 上传文件,并解析出所有的表单字段,包括普通字段和文件字段
    List list = file.parseRequest(request);
    FileItem fileitem=null;
    System.out.println("dd");
    for (Iterator it = list.iterator(); it.hasNext();) {
     fileitem = (FileItem) it.next();   
     //解析表单字的普通字段,即传过来的svrname和dbname,formname,path,unid,divid参数
     if (fileitem.isFormField()){ //普通表单域
      String fieldname = FieldName(); //得到name属性的值
      String value = String("UTF-8");
      if ("svrname".equals(fieldname)){
       svrname = value;
      } else if ("dbname".equals(fieldname)){
       dbname = value;
      } else if ("formname".equals(fieldname)){
       formname = value;
      } else if ("unid".equals(fieldname)){
       unid = value;
      } else if ("divid".equals(fieldname)){
       divid = value;
      } else if ("folder".equals(fieldname)){
       path = value;
      } else if("Filename".equals(fieldname)){
       filename=value;
       System.out.println(filename);
      }
     } else if(null != Name() && 0!= Name().trim().length()){
        //把文件大小转换成KB,MB
        double Size()/1024.0*100)/100.0;
        String suffix="KB";   
        if(size>1000){
        und(size/1000.0*100)/100.0;
        suffix="MB";
       }
       filesize=size+suffix;
       String pa[] = path.split(".nsf/");
       File mkdir = new File(pa[1]);
       if (!ists()) {
        if (mkdir.mkdirs()) {
         System.out.println("创建目录成功");
        }
       }
       realFile = new File(pa[1], filename);
       try {
         // 写入数据
         fileitem.write(realFile);
         System.out.println("上传成功");
       }
       catch (Exception e) {
        System.out.println("上传失败");
        e.printStackTrace();
       }
     }
   }
    fileitem.delete();

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。