ドロップダウン リストで定義されたカテゴリに基づいて、指定したフォルダにファイルをアップロードしたいと考えています。o'reilly API を使用してファイルをアップロードし、ファイルを 1 つの場所に保存しました。2 つのドロップダウン (メイン カテゴリ) を使用しました。ユーザーがオプションを定義した場合、パスが変更され、ファイルが指定されたフォルダーにアップロードされる必要があります。例:「c:\output\aero\int」.パスは動的で、ファイルをアップロードするユーザーinput.myコード
<%@page import="javax.ejb.DuplicateKeyException"%>
<%@ page import="java.io.*,java.sql.*,java.util.zip.*,com.oreilly.servlet.*,com.oreilly.servlet.MultipartRequest,javax.servlet.http.HttpServletResponse" %>
<!DOCTYPE html>
<%
ResultSet rs=null;
Connection connection = null;
String connectionURL = "jdbc:mysql://localhost:3306/ksa";
PreparedStatement psmnt = null;
PreparedStatement psmnt1=null;
PreparedStatement psmnt2=null;
String path;
path="/home/adapco/Desktop/output";
MultipartRequest request2=new MultipartRequest(request,path,1024*1024*1024);
String filename=request2.getFilesystemName("file");
String file1=request2.getParameter("file1");
String selectedValue=request2.getParameter("sel1");
String select1=request2.getParameter("sel2");
String concat=selectedValue+"." +select1;
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");
try
{
java.sql.Date sqlDate = new java.sql.Date(new java.util.Date().getTime());
psmnt1 = connection.prepareStatement("insert into file12(id,file_description,file_path,file_date) values(?,?,?,'"+ sqlDate+"')");
psmnt1.setString(1, concat);
psmnt1.setString(2, file1);
psmnt1.setString(3, f.getPath());
//psmnt.setString(3, "sqlDate");
//String query="select * from file12";
int s=psmnt1.executeUpdate();
if(s>0)
{
System.out.println("Uploaded successfully !");
}
else
{
System.out.println("Error!");
}
psmnt=connection.prepareStatement("select * from file12");
rs=psmnt.executeQuery();
}
catch(Exception e)
{
out.print(" the file already exist"+e);
}
%>
<table cellpadding="15" border="1">
<%
while(rs.next()){
%>
<tr>
<td><%=rs.getString(1)%> </td>
<td><%=rs.getString(2)%> </td>
<td><%=rs.getString(3)%> </td>
<td><%=rs.getString(4)%></td>
</tr>
<%}%>
<a href="index.jsp">home</a><br>
<a href="sample.jsp">upload file</a>
</table>
<%
response.sendRedirect("index.jsp");
%>
ドロップダウンのあるデザイン部分:
<FORM ENCTYPE="multipart/form-data" ACTION="sample2.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><b>Choose the destination folder:</b></td>
<td><INPUT NAME="file1" 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>
私がやろうとしていることは次のとおりです。
MultipartRequest request2=new MultipartRequest(request,"/home/adapco/Desktop/output",1024*1024*1024);
String filename=request2.getFilesystemName("file");
String file1=request2.getParameter("file1");
String selectedValue=request2.getParameter("sel1");
String select1=request2.getParameter("sel2");
String concat=selectedValue+"." +select1;
File f=request2.getFile("file");
//out.println(f.exists()+"----------------"+f.getAbsolutePath());
//out.print(filename);
Double double1=Double.parseDouble(concat);
if(double1==1.1)
{
request2=new MultipartRequest(request,"/home/adapco/Desktop/output/aero/int",1024*1024*1024);
}
上記のコードは私にエラーを示しています
java.io.IOException: Corrupt form data: premature ending
マルチパートオブジェクトだけが作成された場合、それは私を示しています
request2 is not initialized.
ユーザー定義のカテゴリを取得するために連結値を比較しています。