2014-03-19 4 views
0

다음 코드에서 java spring을 사용하여 컨트롤러에 양식을 제출하려고합니다. 파일 요소를 성공적으로 추적하지만 다른 요소를 검색하는 방법을 알지 못합니다 (짧은 이름 및 전체 이름) 값. 나를 도와주세요.컨트롤러에서 양식 요소를 검색하는 방법

<body> 
    <div style="text-align: center; margin-top: 60px;"> 
     <form action="upload" enctype="multipart/form-data"> 
      <input type="hidden" id="shortName" name="michael"> 
      <input type="hidden" id="fullName" name="michael jackson"> 
      Select file: 
      <input type="file" name="dataFile" id="fileAttachment"/><br/><br/> 
       <div style="text-align: center; margin-top: 100px;"> 
        <input style="cursor: pointer;" onmouseover="" onclick="uploadAttachment()" class="dialogbox" type="submit" value="Upload Report" /> 
       </div> 
     </form> 
    </div> 
</body> 

컨트롤러 측 코드 : 컨트롤러에서

@RequestMapping(value = "upload", method=RequestMethod.POST) 
public void upload(HttpServletRequest request, HttpServletResponse response, 
      @RequestPart("dataFile") MultipartFile file 
      ){ 
System.out.println(file.getSize()); 
} 
+0

'@RequestParam String shortName'과'@RequestParam String fullName'을 사용해 보셨습니까? – sp00m

+0

예, 귀하의 구문을 시도했지만 그 도움이 도움이됩니다. 답장을 보내 주셔서 감사합니다. – b22

답변

1

첫 번째 변경 입력 요소를 @PathVariable에 변경과 같이 짧은 이름과 fullName의 모두의 이름 속성을 만들 :

<input type="hidden" id="shortNameId" name="shortName" value="michael"> 
<input type="hidden" id="fullNameId" name="fullName" value="michael jackson"> 

디폴트 값 속성을 제거 할 수 있지만 페이지가 렌더링 될 때 직접 값을 입력하십시오. value = "michael"& value = "michael jackson"은 선택 사항입니다!

그럼 당신은 이런 그 입력 요소를 검색 할 수 있습니다

@RequestMapping(value = "upload", method=RequestMethod.POST) 
public void upload(HttpServletRequest request, HttpServletResponse response, @RequestParam("shortName")String shortName, @RequestParam("fullName")String fullName 
     @RequestPart("dataFile") MultipartFile file 
     ){ .... } 

행운을!

+0

내 쿼리가 해결되었습니다. 감사합니다. – b22

+0

당신을 환영합니다! – M2hp

0

@RequestMapping(value = "/your/url/{formParamenter}", method = RequestMethod.GET) 
    public String yourfunction(@PathVariable("formParameter") Type formParameter{} 

유형의 데이터 (문자열/INT/플로트의 유형입니다, 이런 식으로 뭔가를 시도 .. 기타). 귀하의 경우에는

단지 RequestPart이

관련 문제