Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Issue

Status
Not open for further replies.

mdazam

Programmer
Apr 1, 2005
28
US
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.
 
Hi,

In the HTML form the textarea name is "FileDesc" and in the DB call you are calling it as "DescFile" from the HashMap();

cs1.setString(2,(String) map.get("DescFile"));

Chanage this to

cs1.setString(2,(String) map.get("FileDesc"));

Cheers
Venu
 
Sorry that was typo:

HTML and Servlet has now "FileDesc".

I can able to solve only half. ie When I replaced "file description" <textarea> above the File Upload it worked.
But other unsolved is that I have multiple files. I dont knwo how to comeup with a script which add "file description" <textarea> like file upload filed.

This is JS which add <input type='file' ..> and remove button. how can I modified it to hava <textarea> (description) been added with this JS.

Code:
function AddRowsToTable() {
 var tbl = document.getElementById('tblSample');
 var lastRow = tbl.rows.length;
 var iteration = lastRow;
 var row = tbl.insertRow(lastRow);
 var cellRight = row.insertCell(0);
 var el = document.createElement('input');
 el.setAttribute('type', 'FILE');
 el.setAttribute('name', 'FILE' + iteration);
 el.setAttribute('size', '60');
 el.setAttribute('br', '');
 cellRight.setAttribute('id',iteration)
 cellRight.appendChild(el);

 var aa = document.createElement("input");
 aa.setAttribute('type', 'button');
 aa.setAttribute('value', 'Remove');

 var clickName = new Function("DeleteRow(this)");
 aa.onclick = clickName;
 cellRight.appendChild(aa);

var br = document.creatElement("<BR>");
cellRight.appendChild(br);

Thx
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top