-
400 에러 :: Required request parameter for method parameter type String is not present개발 여정/Error 2021. 9. 16. 19:37
[org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] Resolved [org.springframework.web.bind.MissingServletRequestParameterException: Required request parameter 'content' for method parameter type String is not present]
댓글 내용을 입력했음에도 입력값에 저장이 안됨 원래 코드
let commentContent = $('input[name=commentTxt]').val(); alert(commentContent);
*문제원인
- 현재 댓글입력창은 contentList의 반복문 안에 있음
- 따라서 댓글 다는 곳의 postId를 지정해줘야 어디 위치의 input인지 인식할 수 있음
*문제해결
- input name 버리고 id로 변경
- id 이름 뒤에 postId 붙여줌 (input 위치 지정)
HTML
<input type="text" placeholder="댓글을 입력해주세요." id="commentTxt${content.post.id}"; class="form-control"> <button type="button" class="btn btn-light commentBtn" data-post-id="${content.post.id}">게시</button>
Script
//postId 저장 let postId = $(this).data('post-id'); //content 저장 let commentContent = $('#commentTxt' + postId).val(); if(commentContent == ''){ return; }
'개발 여정 > Error' 카테고리의 다른 글
500 에러 : Duplicate entry for unique index (0) 2021.09.16 500 에러 : Invalid bound statement (not found): com.calmstagram.post.DAO.LikeDAO.selectLikeByUserOrAnd (0) 2021.09.16 500 에러 : java.lang.NumberFormatException: For input string: "userName" (0) 2021.09.16 AJAX 에러 잡기 (0) 2021.09.16 400 에러 :: There was an unexpected error (type=Bad Request, status=400) (0) 2021.09.16