0
     IN JAVA CODE IN JSP as below i m getting null value for field"noOfRecords".
      if (request.getMethod().equalsIgnoreCase("POST")) {
    try
    {
        noOfRecords=Integer.parseInt(request.getParameter("noOfRecords").trim());
    }
    catch(NumberFormatException e)
    {
        throw new Exception("No of records Field should be numeric.");

    }
    catch(NullPointerException e)
    {
        throw new Exception("No of records should be specified.");

    }

HTML 代码如下。

     <BODY leftmargin="0" topmargin="0" marginheight="0" marginwidth="0"   bgcolor="#ffffff"    onLoad="document.customerFileUpload.filePath.focus();">
          <FORM method="post" name="customerFileUpload" action="CustomerFileUpload.jsp" onSubmit="return validate(this);" enctype="multipart/form-data">
     <table width="98%" border="0" cellpadding="2" cellspacing="1" align="center">
            <tr>
                <td width="30%" class="bandcolorlabel">Select File *:</td>
                <td width="70%"><input type="FILE" name="filePath" class="ibox" size="30"></td>
            </tr>
            <tr>
            <td width="30%" class="bandcolorlabel">No Of Records</td>
            <td width="70%"><input type="text" name="noOfRecords" class="ibox" size="30"></td>
            </tr>

        </table>

     <table width="100%" border="0" cellpadding="2" cellspacing="1">
            <tr>
                <td><input type="submit" class="btn" value="Upload" >
                </td>
            </tr>
        </table>
          </form>
     </BODY>
4

1 回答 1

1

由于您使用多部分编码('multipart/form-data')发布,因此参数未按预期显示。

例如,如果您使用的是commons-fileupload,则参数将显示为并且可以使用 FileItem 对象上的“isFormField”方法进行识别。

这个关于 coderanch 的主题解释了如何:coderanch

大多数(每一个)现代网络框架都将这一点抽象出来,顺便让这类事情变得更容易。

于 2009-10-25T05:48:05.130 回答