我无法理解下面的jsp代码中的错误

时间:2015-01-21 16:44:24

标签: jsp

<%

            String rtempfile = File.createTempFile("temp","1").getParent();            
            MultipartRequest multi = new MultipartRequest(request,rtempfile, 15*1024*1024);     // maximum size 15 MB

            Enumeration files = multi.getFileNames();


            String st="insert into documents(filename,type,content)values (?,?,?)";
            PreparedStatement psmt=MyConnection.getConnection().prepareStatement(st);            
            String name="";
            String fileExtesion="";
            File ff =null;
            FileInputStream fin =null;

            while (files.hasMoreElements())
            {
                    name=(String)files.nextElement();                                        
                    ff = multi.getFile(name);
                    fileExtesion = ff.getName().substring(ff.getName().lastIndexOf("."));

                    boolean fileAllowed = fileExtesion.equalsIgnoreCase(".txt")||
                                          fileExtesion.equalsIgnoreCase(".pdf")||
                                          fileExtesion.equalsIgnoreCase(".doc")||
                                          fileExtesion.equalsIgnoreCase(".docx")||
                                          fileExtesion.equalsIgnoreCase(".xls")||
                                          fileExtesion.equalsIgnoreCase(".xlsx");


                    if((ff!=null)&&fileAllowed)
                    {

                            try
                            {
                                    fin=new FileInputStream(ff);
                                    psmt.setString(1, ff.getName());
                                    psmt.setString(2, fileExtesion);
                                    psmt.setBinaryStream(3,(InputStream)fin, (int)(ff.length()));
                                    psmt.setString(4, "Logged User name or ID");        // pass the user name or id 
                                    boolean sss = psmt.execute();

                                    out.print("uploaded successfully..");
                                    out.print("<br/> Go to <a href='downloadfile.jsp'>Download</a> page");
                            }

                            catch(Exception e)
                            {
                                    out.print("Failed due to " + e);
                            }


                            finally
                            {
                            // next statement is must otherwise file will not be deleted from the temp as fin using f.
                             // its necessary to put outside otherwise at the time of exception file will not be closed.
                                    fin.close();
                                    ff.delete();
                            }
                    }
                    else
                    {
                           out.print("Please select the correct file...");
                    }// end of if and else
            }// end of while

            MyConnection.CloseConnection();            
        %>

org.apache.jasper.JasperException: An exception occurred processing JSP page /uploadfile.jsp at line 32

29:             
30: 
31:             String st="insert into documents(filename,type,content) values (?,?,?)";
32:             PreparedStatement psmt=MyConnection.getConnection().prepareStatement(st);
33:             
34:                         
35:             

0 个答案:

没有答案