2011-07-11 13 views
1

ちょうど3日前私はPDFファイルをアップロードしようとしているときに次のエラーメッセージが表示されています...なぜ今は動作していないのかわかりません....私は何も変えなかった、それはサーバーになる可能性がありますか?PDFファイルをJAVAを使用してアップロード

これは私が取得していますエラーです:これは

java.lang.IndexOutOfBoundsException 
java.io.FileOutputStream.writeBytes(Native Method) 
java.io.FileOutputStream.write(FileOutputStream.java:260) 

例外

org.apache.jasper.JasperException: Exception in JSP: /drawingUp.jsp:48 

45:   File savedFile = new File(folder +"/IngDemo/drawings/"+saveFile) ; 
46:   FileOutputStream fileOut = new FileOutputStream(savedFile); 
47:   //FileOutputStream fileOut = new FileOutputStream(savedFile); 
48:   fileOut.write(dataBytes, startPos, (endPos - startPos)); 
49:   fileOut.flush(); 
50:   fileOut.close(); 

それが何ができるかのいずれかの手がかりをいただければ幸いです..... おかげ

をコードの詳細:

String contentType = request.getContentType(); 
//here we are checking the content type is not equal to Null and 
//as well as the passed data from multipart/form-data is greater than or 
//equal to 0 
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) 
{ 
    DataInputStream in = new DataInputStream(request.getInputStream()); 
    //we are taking the length of Content type data 
    int formDataLength = request.getContentLength(); 
    byte dataBytes[] = new byte[formDataLength]; 
    int byteRead = 0; 
    int totalBytesRead = 0; 
    //this loop converting the uploaded file into byte code 
    while (totalBytesRead < formDataLength) { 
     byteRead = in.read(dataBytes, totalBytesRead,formDataLength); 
     totalBytesRead += byteRead; 
     } 
    String file = new String(dataBytes); 
    //for saving the file name 
    String saveFile = file.substring(file.indexOf("filename=\"") + 10); 
    saveFile = saveFile.substring(0, saveFile.indexOf("\n")); 
    saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1,saveFile.indexOf("\"")); 
    int lastIndex = contentType.lastIndexOf("="); 
    String boundary = contentType.substring(lastIndex + 1,contentType.length()); 
    int pos; 
    //extracting the index of file 
    pos = file.indexOf("filename=\""); 
    pos = file.indexOf("\n", pos) + 1; 
    pos = file.indexOf("\n", pos) + 1; 
    pos = file.indexOf("\n", pos) + 1; 
    int boundaryLocation = file.indexOf(boundary, pos) - 4; 
    int startPos = ((file.substring(0, pos)).getBytes()).length; 
    int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length; 
    // creating a new file with the same name and writing the 
//content in new file 
    String folder = (String) new File(config.getServletContext().getRealPath("/")).getParent(); 
    folder= (String)folder.replace(File.separatorChar, '/'); 
    File savedFile = new File(folder +"/IngDemo/drawings/"+saveFile) ; 
    FileOutputStream fileOut = new FileOutputStream(savedFile); 
    //FileOutputStream fileOut = new FileOutputStream(savedFile); 
    fileOut.write(dataBytes, startPos, (endPos - startPos)); 
    fileOut.flush(); 
    fileOut.close(); 
+1

コードが表示されているかわかりません...明らかな問題は、startPosとendPosがどこから来たのかです。一方または両方が無効です。 –

+0

私はあなたのコメントのおかげで、多くのコードを追加しました – Sheeyla

答えて

0

endPosとstartPosはどのように計算されますか?あなたの問題は、これらの値の一方または両方が間違っていることがほぼ確実です。

+0

これは完全なコードです – Sheeyla

+0

私はコードの多くを追加しました。私は何か間違って見ることができません。 – Sheeyla

+0

エディタの "コード"ボタンを使用してコードをフォーマットしてください。 – jkraybill

0

あなたのコードでは、ある特定の数の改行や、=文字の配置などが含まれていると仮定しています。end > startの前提条件を確認するために、真実を保持するなど、エラーの突然の出現はあなたに表示されます。

+0

マット、あなたは終わりの開始が起こっている前に、もし、 – Sheeyla