关闭IE的时候你又不能关IE然后通知服务器。你得把观念搞好。这是web程序!!

解决方案 »

  1.   

    我不知道你想实现什么功能,但是有一点。你上传一个数据也是很简单的啊。
    如果你用servlet,然后在里面调用一个插入的方法不就完事了?
      

  2.   

    页面发送请求
    server返回响应
    只能这么交互
    关闭页面无法控制server啊
      

  3.   

    没有  我上传的文件才几十KB  有的时候成功  有的时候上传就没响应  被迫关闭显示器  然后再登录进去 就进不去那个页面了 因为那个连接没断开 
    我想完成从A页面提交附件 B页面接收附件   然后在B页面将文件上传  并且将这个文件写入数据库  然后关闭数据库连接 把文件删除  就是这么一个操作流程
    <%!
      //这儿需要修改成您的数据库连接信息
      public Connection conn = null;
      public String docid = "";
      public String filename = "";
      public int filesize = 0;
    %>
    <%
      String js = null;
      Userinfo userinfo = null;
      String stu_id = null;
      String tch_id = null;
      stu_id = request.getParameter("stuid");
      int xtzl = 0;
      int wxzs = 0;
      int zy = 0;
      int bysjzl = 0;
      try {
        xtzl = Integer.parseInt(request.getParameter("xtzl"));
      }
      catch (Exception e) {
        xtzl = 0;
      }
      try {
        wxzs = Integer.parseInt(request.getParameter("wxzs"));
      }
      catch (Exception e) {
        wxzs = 0;
      }
      try {
        zy = Integer.parseInt(request.getParameter("zy"));
      }
      catch (Exception e) {
        zy = 0;
      }
      try {
        bysjzl = Integer.parseInt(request.getParameter("bysjzl"));
      }
      catch (Exception e) {
        bysjzl = 0;
      }
      int op = -1;
      if (request.getParameter("op") != null)
        op = Integer.parseInt(request.getParameter("op"));
      mySmartUpload.initialize(pageContext);
      try {
        mySmartUpload.upload();
        mySmartUpload.save("/thesisdocuments/bysjpyjs");
      }
      catch (SmartUploadException e) {
        out.println(MsgLang.uploaderr());
      }
      coghatool.wordprocess.File myFile = null;
      docid = mySmartUpload.getRequest().getParameter("docid");
      for (int i = 0; i < mySmartUpload.getFiles().getCount(); i++) {
        myFile = mySmartUpload.getFiles().getFile(i);
        if (!myFile.isMissing()) {
          filename = myFile.getFileName();
          filesize = myFile.getSize();
          if (myFile.getFieldName().equalsIgnoreCase("EDITFILE")) { //正文文件
            /*System.out.println("处理正文文件");
                     System.out.println("filename=" + filename);
                     System.out.println("filesize=" + filesize);
                     System.out.println("myFile.getFieldName()=" + myFile.getFieldName());*/
            String filename_path = application.getRealPath("/") + "thesisdocuments\\bysjpyjs\\" + filename;
            java.io.File tfile = null;
            java.io.InputStream inStream = null;
            PreparedStatement ps = null;
            Statement stmt = null;
            try {
              int count = 0;
              tfile = new java.io.File(filename_path);
              inStream = new java.io.FileInputStream(tfile);
              conn = ConnectDB.ReturnConnection();
              if (op == 1) { //另存
                String sql = "insert into t_bysjpyjs(stu_id,filename,filesize,filedata,xtzl,wxzs,zy,bysjzl,date) values(?,?,?,?,?,?,?,?,getdate())";
                int total = xtzl + wxzs + zy + bysjzl;
                String str2 = "update t_stuinfo set py_thesis_score=" + total + " where stu_id='" + stu_id + "';";
                ps = conn.prepareStatement(sql);
                stmt = conn.createStatement();
                ps.setString(1, stu_id);
                ps.setString(2, filename);
                ps.setInt(3, filesize);
                ps.setBinaryStream(4, inStream, inStream.available());
                ps.setInt(5, xtzl);
                ps.setInt(6, wxzs);
                ps.setInt(7, zy);
                ps.setInt(8, bysjzl);
                count = ps.executeUpdate();
                stmt.executeUpdate(str2);
              }
              else if (op == 0) { //保存
                String strSql = "";
                strSql = "update t_bysjpyjs set filename=?,filesize=?,filedata=?,xtzl=?,wxzs=?,zy=?,bysjzl=?,date=getdate() where stu_id='" + stu_id + "'";
                int total = xtzl + wxzs + zy + bysjzl;
                String str2 = "update t_stuinfo set py_thesis_score=" + total + " where stu_id='" + stu_id + "';";
                ps = conn.prepareStatement(strSql);
                stmt = conn.createStatement();
                ps.setString(1, filename);
                ps.setInt(2, filesize);
                ps.setBinaryStream(3, inStream, inStream.available());
                ps.setInt(4, xtzl);
                ps.setInt(5, wxzs);
                ps.setInt(6, zy);
                ps.setInt(7, bysjzl);
                count = ps.executeUpdate();
                stmt.executeUpdate(str2);
              }
              if (count > 0) {
                out.println(MsgLang.uploadsuccess(filename, filesize));
              }
              else {
                out.println(MsgLang.uploadfailed2());
              }
            }
            catch (Exception e) {
              e.printStackTrace();
              out.println("发生错误: " + e.toString());
            }
            finally {
              try {
                if (stmt != null)
                  stmt.close();
                if (ps != null)
                  ps.close();
                if (conn != null)
                  conn.close();
                if (inStream != null)
                  inStream.close();
                if (tfile != null)
                  tfile.delete();
              }
              catch (SQLException e) {
                e.printStackTrace();
              }
            }
          }
        }
      }
    %>
      

  4.   

    ps.setBinaryStream(4, inStream, inStream.available())感觉是这里的问题
    保存文件到数据库中应该也要和读取文件一样,要将文件以字节流的方式写入到数据库中另外,你的页面代码和业务代码能不能分开写……