I am trying to submit a form with text fields, text area, file field etc in a JSP form. I am using commons file upload for this form.
Here is my JSP form:
<form name="add_product_form" id="add_product_form" enctype="multipart/form-data" method="post" action="Product.Add">
<div id="form-body">
<div id="lebel">
<font color="red">*</font>Product Name:
</div>
<div id="field">
<input type="text" name="product_name" id="product_name" value="">
</div>
<div id="lebel">
<font color="red">*</font>SKU No:
</div>
<div id="field">
<input type="text" name="sku_no" id="sku_no" value="">
</div>
<div id="lebel">
<font color="red"> </font>In Date:
</div>
<div id="field">
<input type="text" name="in_date" id="in_date" value="">
</div>
<div id="lebel">
<font color="red"> </font>Upload Image:
</div>
<div id="field">
<input type="file" name="upload_image" id="upload_image" value="">
</div>
<div id="lebel">
<font color="red"> </font>Description:
</div>
<div id="field">
<textarea name="description" id="description"></textarea>
</div>
<div id="lebel">
</div>
<div id="button_field">
<input type="submit" name="add_product_button" id="add_product_button" value="Add Product">
</div>
</div>
</form>
I am getting the value of the text fields using following methods.
List fileItems = upload.parseRequest(request);
// Process the uploaded file items
Iterator i = fileItems.iterator();
while ( i.hasNext () )
{
FileItem fi = (FileItem)i.next();
if ( !fi.isFormField () )
{
// Get the uploaded file parameters
String fieldName = fi.getFieldName();
String value = fi.getString();
fileName = fi.getName();
String contentType = fi.getContentType();
boolean isInMemory = fi.isInMemory();
long sizeInBytes = fi.getSize();
// Write the file
if( fileName.lastIndexOf("\\") >= 0 )
{
file = new File( filePath +
fileName.substring( fileName.lastIndexOf("\\"))) ;
}
else
{
file = new File( filePath +
fileName.substring(fileName.lastIndexOf("\\")+1)) ;
}
fi.write( file ) ;
}
else
{
String name = fi.getFieldName();
String value = fi.getString();
if( name.equals("product_name") )
{
productName = value;
}
else if( name.equals("sku_no") )
{
skuNo = value;
}
else if( name.equals("in_date") )
{
newDateString = value;
}
else if( name.equals("description") )
{
productDesc = value;
}
}
}
But I am not getting the value of "TextArea" I have used in my form with name "descripton".
Can anyone help me in getting the value of this text area when submitting the form.
Thanks
Could not find the direct solution.
To implement this I used a hidden field and jquery.
On clicking the submit button, I smet the value of teh text area in the hidden field, then submit the form.
Here is the jquery code:
$('#add_product_button').click(function()
{
var description = $("#description").val();
$("#hidden_description").val(description);
$("add_product_form").submit();
});