0

クライアントがファイルをアップロードし、ファイルがデータベースに保存されるプログラムがあります。私のコンピューターで Java を更新する前は、私のプロジェクトは正常に機能していました。今、私はFileNotFoundException. エクリプスは私に言っています:

JAR ファイル C:\Program Files\Java\jre7\lib\rt.jar にはソースが添付されていません。

誰でもこの問題に遭遇しますか?

ファイルをアップロードするための私のサーブレット コードは標準です。

if (!ServletFileUpload.isMultipartContent(request))
    {return;}

try 
{ 
  List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
  courseID = items.get(0).getString();
  homeworkID = items.get(1).getString();
  File storeFile = new File(items.get(2).getName());
  String fileName = storeFile.getName();
  String mimeType = new MimetypesFileTypeMap().getContentType(storeFile); //for putting file into database
  putFileIntoDB(uName, courseID, homeworkID, fileName, mimeType, storeFile);
}//try
 catch (Exception ex)
 {
   request.setAttribute("msg", "There was an error: " + ex.getMessage());
   request.getRequestDispatcher("/upload.jsp").forward(request, response);
  }

FileInputStream が行 fis=new FileInputStream(f) で作成されると、putFileIntoDB メソッドでエラーが検出されます。

void putFileIntoDB(String username, String courseID, String homeworkID, String fileName, String mime, File f) throws SQLException, IOException
{   
    FileInputStream fis = null;
    java.sql.PreparedStatement pstmt = null;
    java.sql.Connection conn = null;
    try {
            conn = ConnectionManager.getConnection();
            conn.setAutoCommit(true);

            fis = new FileInputStream(f);

            pstmt = conn.prepareStatement("insert into files(username, courseID, assignmentID, fileName, mimeType, contents) values (?, ?, ?, ?, ?, ?)");
            pstmt.setString(1, username);
            pstmt.setString(2, courseID);
            pstmt.setString(3, homeworkID);
            pstmt.setString(4, fileName);
            pstmt.setString(5, mime);
            pstmt.setAsciiStream(6, fis, (int) f.length());

            pstmt.executeUpdate();
            conn.commit();
        }
    catch (Exception e)
    {
      System.err.println("Error: " + e.getMessage());
      e.printStackTrace();
    } 
    finally
    {
      pstmt.close();
      fis.close();
      conn.close();
    }
}

他の誰かがこの問題に遭遇しましたか?

4

1 に答える 1

1

以下の手順を試してください。

ステップ 1 - JRE ではなく JDK を使用するように Eclilpse を構成します。

Window->Preferences->Java->Installed JREs
Click "Add", "Standard VM", "Next"
For "JRE Home" click "Directory"
Locate your JDK directory...
Ex: C:\java\jdk1.6.0_24
Click "Finish"
Next check the JDK vs the JRE that is listed.
Click "Ok"

ステップ 2 - JDK を使用するようにプロジェクトを構成します。これは、「インストール済み JRE」として JRE を使用して作成されたためです。新しいプロジェクトは問題ないはずです。

Right click the project's name.
Choose "Properties", "Java Build Path"
Click the tab "Libraries".
Click "Add Libraries", select "JRE System Library", Next
Select the bottom item: Workspace default JRE (jdk1.x.x. etc....)
(Notice that it is now a JDK and not the JRE!)
Click "Finish"
Now remove the JRE libarary so you only have the JDK library.
ex: JRE System Library [JavaSE-1.6]
Click "OK"
于 2013-03-18T10:01:25.080 に答える