Hi experts,
I had a servlet which upload(write) files to server. Now I was told to have describtion of each file along with the file itself. I try my all possible ways but didnt got thru. Can anyone help me out. 1st is it possible to submit <textarea> along with the type="file" with form enctype="multipart/form-data". Bcoz I didnt got the value of <textarea> ?
2. Once I get <textarea> value what modification should I make in my below code to write this values to DB.
<----Servlet code ----->
<code>
DiskFileUpload upload = new DiskFileUpload();
List items = upload.parseRequest(req);
Iterator iter = items.iterator();
Map map = new HashMap();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
System.out.println("Form has a field");
if (item.isFormField())
{
String name = item.getFieldName();
String value = item.getString().trim();
map.put(name,value);
System.out.println("Name:"+name+ " Value:" +value+);
}
else
{
System.out.println("Else Part: Operating on Files");
String storedProcCall1 = "{call apMaintFObjects(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
CallableStatement cs1 = connection.prepareCall(storedProcCall1);
File cfile=new File(item.getName().replace('\\', '/'));
System.out.println("item.getName() -> " + item.getName());
System.out.println("cFile.getName() -> " + cfile.getName());
cs1.setString(1,cfile.getName());
cs1.setString(2,(String) map.get("DescFile")); [need to get this value who ???????]
cs1.setString(3,(String) map.get("date"));
cs1.setString(4,(String) map.get("Product"));
cs1.executeQuery();
}
....
</code>
(above code write only data into DB. and other code below which I hv not copied actual upload (write) file to server.
.......
<--end of servlet-->
I'm passing 'date' and 'Product' as a hidden filed so I'm getting the values. But I unable to get the desciption value. When I pass description values ushing hidden filed I can able to get .
My JSP page....
<code>
<form name="form" action="servletcall" method="post" enctype="multipart/form-data">
<input type="hidden" name="product" value="xyz">
<input type="hidden" name="date" value="6/6/05">
<input type="file" size="60" name="FILE1"></td>
<textarea rows="4" name="FileDesc" cols="40"></textarea>
</form>
</code>
Thanks for your time.
I had a servlet which upload(write) files to server. Now I was told to have describtion of each file along with the file itself. I try my all possible ways but didnt got thru. Can anyone help me out. 1st is it possible to submit <textarea> along with the type="file" with form enctype="multipart/form-data". Bcoz I didnt got the value of <textarea> ?
2. Once I get <textarea> value what modification should I make in my below code to write this values to DB.
<----Servlet code ----->
<code>
DiskFileUpload upload = new DiskFileUpload();
List items = upload.parseRequest(req);
Iterator iter = items.iterator();
Map map = new HashMap();
while (iter.hasNext()) {
FileItem item = (FileItem) iter.next();
System.out.println("Form has a field");
if (item.isFormField())
{
String name = item.getFieldName();
String value = item.getString().trim();
map.put(name,value);
System.out.println("Name:"+name+ " Value:" +value+);
}
else
{
System.out.println("Else Part: Operating on Files");
String storedProcCall1 = "{call apMaintFObjects(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
CallableStatement cs1 = connection.prepareCall(storedProcCall1);
File cfile=new File(item.getName().replace('\\', '/'));
System.out.println("item.getName() -> " + item.getName());
System.out.println("cFile.getName() -> " + cfile.getName());
cs1.setString(1,cfile.getName());
cs1.setString(2,(String) map.get("DescFile")); [need to get this value who ???????]
cs1.setString(3,(String) map.get("date"));
cs1.setString(4,(String) map.get("Product"));
cs1.executeQuery();
}
....
</code>
(above code write only data into DB. and other code below which I hv not copied actual upload (write) file to server.
.......
<--end of servlet-->
I'm passing 'date' and 'Product' as a hidden filed so I'm getting the values. But I unable to get the desciption value. When I pass description values ushing hidden filed I can able to get .
My JSP page....
<code>
<form name="form" action="servletcall" method="post" enctype="multipart/form-data">
<input type="hidden" name="product" value="xyz">
<input type="hidden" name="date" value="6/6/05">
<input type="file" size="60" name="FILE1"></td>
<textarea rows="4" name="FileDesc" cols="40"></textarea>
</form>
</code>
Thanks for your time.