inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

묻고 답해요

173만명의 커뮤니티!! 함께 토론해봐요.

새창으로 form submit() 할 때 csrf 토큰문제 질문드려요

미해결

<body> <form:form id="gotoPopupPreview" name="gotoPopupPreview" method="post" action=""> <input type="hidden" name="isPreview" value="Y"> <input type="hidden" name="nttId" value="${searchVO.nttId}"> ...(생략) </form:form> <script> function openPreview(url, target, otherData){ var f = $("#gotoPopupPreview"); f.attr('action', url); f.attr('target', target); ...(생략) window.open('', target); f.submit(); } $("submitBtn").click(function(){ var otherData = '어쩌구저쩌구'; openPreview("http://www.test.or.kr/", '테스트', otherData); }); </script> </body> 위 코드와 같이 form 태그를 만들어두고 스크립트에서 새 창을 열어 submit을 보냈습니다. 근데 서버에서 AccessDeniedException : org.springframework.security.web.csrf.MissingCsrfTokenException: Could not verify the provided CSRF token because your session was not found. result :::: {"result" : "fail", "message" : "Could not verify the provided CSRF token because your session was not found."} 이렇게 csrf 토큰이 없다고 뜨네요.. 처음엔 <input type="hidden" name="$csrf.parameterName}" value="${csrf.token}" /> 이렇게 form태그 안에 직접 넣었다가 form taglib을 쓰면 자동으로 토큰을 넣어준다길래 위와 같이 바꾼건데요, 두 경우 모두 토큰이 잘 들어있는 것으로 보이는데 왜 저런 exception이 뜨는 지 모르겠습니다ㅠ 아무래도 새 창으로 띄우는 게 문제일까요? 이 경우에는 토큰을 어떻게 넣어줘야 할까요? T.T

  • csrf
  • form
  • submit
  • jsp
김신희 댓글 1 좋아요 0 조회수 679

인기 태그

인프런 TOP Writers

주간 인기글