الحصول على باطل على request.getParameter () على تقديم النموذج في التعليمات البرمجية جافا؟

StackOverflow https://stackoverflow.com/questions/1620013

  •  06-07-2019
  •  | 
  •  

سؤال

     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.");

    }

وCODE 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>
هل كانت مفيدة؟

المحلول

ومنذ قمت بنشر باستخدام ترميز متعدد الأجزاء ( 'متعددة الأجزاء / شكل بيانات') المعلمات ليست موجودة كما هو متوقع.

إذا على سبيل المثال كنت تستخدم المشاعات-fileupload المعلمات سيكون حاضرا كما ويمكن تمييزها باستخدام طريقة "isFormField" على الكائن FileItem.

وهذا THEAD على coderanch يوضح كيفية القيام بذلك: coderanch

ومعظم (كل) webframeworks الحديثة مجردة هذا بعيدا وجعل هذا النوع من الأشياء أسهل بكثير من جانب الطريق.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top