请问:我想在上传文件的同时提交其他的信息到库里,应该怎么做啊?
使用form表单

解决方案 »

  1.   

    <%@ page contentType="text/html; charset=gb2312" language="java"
        import="java.sql.*"
        import="java.util.*,
       com.jspsmart.upload.*"
        import="com.document.*,
                com.util.*"  %><HTML>
    <BODY BGCOLOR="#666666">
    <HR>
    <%
     boolean foundErr = false;
     String myFileName = "";
     String uploadPath = "";
     String errMsg="";
     SmartUpload su = new SmartUpload();
     com.jspsmart.upload.Request req = su.getRequest(); try {
          su.initialize(pageContext);
          su.setTotalMaxFileSize(10*1024*1024);
          su.upload();
          java.util.Date nowTime=new java.util.Date();//声明时间变量
          com.jspsmart.upload.File myFile = su.getFiles().getFile(0);
          if(!myFile.isMissing()){
              myFileName = myFile.getFileName();
              if (myFile.getSize()<10*1024*1024) {
                  if (myFile.getFileExt().toLowerCase().equals("doc") ||
                      myFile.getFileExt().toLowerCase().equals("pdf") ||
                      myFile.getFileExt().toLowerCase().equals("txt") ||
                     myFile.getFileExt().toLowerCase().equals("htm") ||
                      myFile.getFileExt().toLowerCase().equals("html")) {
                      //uploadPath = getServletContext().getRealPath("/") +
                      //             getServletContext().getInitParameter("document");
                      uploadPath = getServletContext().getInitParameter("document");
                      myFile.saveAs(uploadPath + String.valueOf(nowTime.getTime()) + "." +
                                    myFile.getFileExt().toLowerCase());//路径+up+时间+扩展名
                  } else {
                      errMsg = errMsg + "上传文档格式只能为doc,txt,pdf,html<br/>";
                      foundErr = true;
                  }
              } else {
                  errMsg = errMsg + "上传文档大小不可超过10M!<br/>";
                  foundErr = true;
              }
          } else {
            //errMsg = errMsg + "请输入要上传更新文档!<br/>";
            //foundErr = true;
          }
          //错误判断
          if (foundErr) {
                        out.println("<table width=680 height=450 border=0 cellpadding=0 cellspacing=0><tr><td height=297 align=center valign=top bgcolor=#666666> <table width=100% border=0 align=center cellspacing=0 cellpadding=0> <tr> <td align=center height=20>"+errMsg+"</td> </tr> </table></td></tr></table>");
          } else {
              //级别判断
              String docRight = req.getParameter("doc_right");
              String usr_right = req.getParameter("usr_right");
              if (CommonUtil.changeToInt(docRight) < CommonUtil.changeToInt(usr_right)) {
    out.println("<table width=680 height=450 border=0 cellpadding=0 cellspacing=0><tr><td height=297 align=center valign=top bgcolor=#666666> <table width=100% border=0 align=center cellspacing=0 cellpadding=0> <tr> <td align=center height=20>文档级别设置过高!</td> </tr> </table></td></tr></table>");
              } else {
              //文档名称
              String docName = req.getParameter("doc_name");
              //更新内容
              String docRework = req.getParameter("doc_rework");
              //路径
              String docPath = req.getParameter("doc_path");
              //文档状态
              String docState = req.getParameter("doc_state");
              //版本
              String docEdition = req.getParameter("doc_edition");
              //简介
              String docBrief = req.getParameter("doc_brief");
              //文档类
              String docClass = req.getParameter("doc_class");
              //更新者所属部门
              String depId = req.getParameter("dep_id");
              depId = req.
              //更新者
              String usrId = req.getParameter("usr_id");
              //数据库记录数
              String dbId = req.getParameter("doc_db_id");
              //仅限本部门标志
              int depSelf = CommonUtil.parseInt(req.getParameter("depself"));
              if(myFileName.equals("")) {
    myFileName = docName;
              }
              SelDocDBS seldocc = new SelDocDBS();
              List doccList = seldocc.oneDocc(CommonUtil.parseInt(docClass));
              com.document.Doc_class docc = (com.document.Doc_class) doccList.get(0);
              //生成文档实例
              com.document.Document doc = new Document();
      List docList = seldocc.document(CommonUtil.parseInt(dbId));
      doc = (Document)docList.get(0);
              //doc.setDoc_db_id(new Integer(CommonUtil.parseInt(dbId)));
              doc.setDoc_class(docc);
              doc.setDoc_class_id(new Integer(CommonUtil.parseInt(docClass)));
              doc.setDoc_class_name(docc.getDc_class_name());
              doc.setDoc_brief(docBrief);
              doc.setDoc_rework(docRework);
              doc.setDoc_mod_dep_id(new Integer(depId));
              doc.setDoc_modificator(new Integer(usrId));
              doc.setDoc_edition(docEdition);
              doc.setDoc_name(myFileName);
              doc.setDoc_path(uploadPath+String.valueOf(nowTime.getTime())+"."+myFile.getFileExt().toLowerCase());
              doc.setDoc_right(new Integer(CommonUtil.changeToInt(docRight)));
              doc.setDoc_state(docState);
      doc.setDoc_mod_upload(nowTime);
      doc.setIsupdate(new Integer(1));
              doc.setDepself(new Integer(depSelf));
              //更新文档
              UpdDocDBS updDoc = new UpdDocDBS();
              updDoc.updDoc(doc);
              //文档更新成功
              out.println("<table width=680 height=450 border=0 cellpadding=0 cellspacing=0><tr><td height=297 align=center valign=top bgcolor=#666666> <table width=100% border=0 align=center cellspacing=0 cellpadding=0> <tr> <td align=center height=20>文档更新成功!</td> </tr> </table></td></tr></table>");
              }
          }
      } catch (Exception e) {
          out.println(e.toString());
      }
    %>
    </BODY>
    </HTML>