java - 文件上传 JSP 和 Servlet 2.5 未获取 Textarea 值

标签 java jsp apache-commons-fileupload servlet-2.5

我正在尝试在 JSP 表单中提交包含文本字段、文本区域、文件字段等的表单。我正在使用此表单的公共(public)文件上传。

这是我的 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>

我使用以下方法获取文本字段的值。

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”的值。

任何人都可以帮我在提交表单时获取此文本区域的值。

谢谢

最佳答案

它有一些问题。您可以为文本框提供样式,使其看起来像文本区域,这将帮助您

关于java - 文件上传 JSP 和 Servlet 2.5 未获取 Textarea 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20327019/

相关文章:

java - InputStream 在 Apache FileUpload API 中关闭

java - 任何更好的分配字符串值的方法,消除 Java 中的多个 If Else block

java - 如何使用 JAXB 对元素进行逻辑分组?

java - 我想在图形用户界面中绘制矩形

java - JCombobox 中的结果集

java - JSP EL 评估问题

java - 如何在java中使用while循环检索匹配的id记录

java - @WebServlet 注解 web.xml 欢迎文件

java - 如何使用 Commons FileUpload 设置用于存储文件上传的文件夹

java - 为什么我的图像出现乱码?