通过文件上传JSP和Servet 2.5无法获得“文本区域"值 [英] Not getting Text Area value with file upload JSP and Servet 2.5

查看:99
本文介绍了通过文件上传JSP和Servet 2.5无法获得“文本区域"值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以JSP表单提交包含文本字段,文本区域,文件字段等的表单.我正在为此表格使用Commons文件上传.

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.

这是我的JSP表单:

<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">&nbsp;</font>In Date:
        </div>
        <div id="field">
            <input type="text" name="in_date" id="in_date" value="">
        </div>
        <div id="lebel">
            <font color="red">&nbsp;</font>Upload Image:
        </div>
        <div id="field">
            <input type="file" name="upload_image" id="upload_image" value="">
        </div>
        <div id="lebel">
            <font color="red">&nbsp;</font>Description:
        </div>
        <div id="field">
            <textarea name="description" id="description"></textarea>
        </div>
        <div id="lebel">
            &nbsp;
        </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;
        }
    }
}

但是我没有得到我在表单中使用的名称为"descripton"的"TextArea"的值.

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.

谢谢

推荐答案

找不到直接解决方案.

为实现这一点,我使用了一个隐藏字段和jquery.

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.

这是jquery代码:

Here is the jquery code:

$('#add_product_button').click(function()
{
        var description = $("#description").val();
        $("#hidden_description").val(description);
        $("add_product_form").submit();
});

这篇关于通过文件上传JSP和Servet 2.5无法获得“文本区域"值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆