Java 코드에서 양식 제출시 요청시 null을 받으시겠습니까?
-
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.");
}
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>
해결책
Multipart Encoding ( 'multipart/form-data')을 사용하여 게시하므로 매개 변수는 예상대로 존재하지 않습니다.
예를 들어 사용중인 경우 Commons-FileUpload 파라미터는 FileItem 객체의 'Isformfield'메소드를 사용하여 다음과 같이 존재하고 식별 할 수 있습니다.
Coderanch 의이 thead는 다음과 같은 방법을 설명합니다. Coderanch
대부분의 (모든) 현대 웹 프레임 워크는 이것을 추상화하고 이런 종류의 것들을 훨씬 쉽게 만듭니다.
제휴하지 않습니다 StackOverflow