1

こんにちは私はフォーム「java.io.IOException:破損したフォームデータ:時期尚早の終了」を送信するとこのエラーが発生します。既存のスクリプトレット内にこのコードを追加すると発生します

String selectedValue=request.getParameter("sel1");
//out.println("Selected Value is: "+selectedValue);

String select1=request.getParameter("sel2");
//out.println("selected values is:"+select1);

String concat=selectedValue+"." +select1;
out.println(""+concat);

私の既存のスクリプトレット

<%@ page import="java.io.*,java.sql.*,java.util.zip.*,com.oreilly.servlet.*" %>
<%
try
 {    
   //if i include here,i can retrive the values but i cant upload the file into database,shows me "java.io.IOException: Corrupt form data: premature ending "
 String selectedValue=request.getParameter("sel1");
//out.println("Selected Value is: "+selectedValue);

String select1=request.getParameter("sel2");
//out.println("selected values is:"+select1);

String concat=selectedValue+"." +select1;
out.println(""+concat);

Connection connection = null;
String connectionURL = "jdbc:mysql://localhost:3306/ksa";
PreparedStatement psmnt = null;
    MultipartRequest request2=new MultipartRequest(request,"/home/adapco/Desktop/output",1024*1024*1024);
String filename=request2.getFilesystemName("file");

File f=request2.getFile("file");
out.println(f.exists()+"----------------"+f.getAbsolutePath());
out.print(filename);
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection(connectionURL, "root", "root");
psmnt = connection.prepareStatement("insert into file1(file_path) values(?)");
psmnt.setString(1, f.getPath());
int s = psmnt.executeUpdate();

 //if i include here it shows me null.null

String selectedValue=request.getParameter("sel1");
//out.println("Selected Value is: "+selectedValue);

String select1=request.getParameter("sel2");
//out.println("selected values is:"+select1);

String concat=selectedValue+"." +select1;
out.println(""+concat);

if(s>0)
{
 System.out.println("Uploaded successfully !");
}
else
{
 System.out.println("Error!");
}
}
catch(Exception e)
{
  out.print("-----------error--------------"+e);
}
%>

既存のコードからコードを除外すると、正常に機能します。catchの後またはtryブロックの最後にコードを含めると、nullが表示されることがあります。ドロップダウンのインデックス値を読み取って連結する必要があります。ドット付き。エラーは「null.null」でした。実際の結果は次のようになります。1.1。これが私のHTMLコードです

<%@ page language="java" %>
<HTML>
   <FORM ENCTYPE="multipart/form-data" ACTION="uploadFile.jsp" METHOD=POST>
    <center>
   <table bgcolor=#38ACEC>
    <tr>
    <center><td colspan="2" align="center"><B>UPLOAD THE FILE</B><center></td>
     </tr>
    <tr><td colspan="2" align="center"> </td></tr>
    <tr><td><b>Choose the file To Upload:</b></td>
    <td><INPUT NAME="file" TYPE="file"></td>
    </tr>
    <tr><td><select name="sel1">
     <option value="1">Aerospace</option>
     <option value="2">Automotive</option>
     <option value="3">Energy</option>
     <option value="4">IC Engines</option>
     <option value="5">Wind</option>
       <option value="6">Turbo</option>
      <option value="7">IT</option>
      <option value="8">Training</option>
     </select>
     <br>
     <select name="sel2">
     <option value="1">Internal</option>
     <option value="2">Demos</option>
     <option value="3">Best Practice</option>
       <option value="4">Marketing</option>
     <option value="5">Papers & public</option>
     <option value="6">Validation</option>
     <option value="7">Training</option>
      </select></td></tr>
      <tr><td colspan="2" align="center"> </td></tr>
      <tr><td colspan="2" align="center"><input type="submit" value="Send File"> </td></tr>
     <table>
   </center>
    </FORM>
   </html>  
4

1 に答える 1

1

MultipartRequestこれはあなたが持っている非常に古い例です。いくつかのバグがあるOreillyマルチパートパーサー。概要については、関連する質問を参照してください。破損したフォームデータ:早期終了(解決済み)。むしろ、Apache Commons FileUploadを使用するか、新しいサーブレット3.0の組み込みrequest.getPart()メソッドのみを使用してください。「 JSP/サーブレットにファイルをアップロードする方法」も参照してください。

于 2012-04-24T06:57:36.887 に答える