redirect시 @RequestParam이 동작을 안합니다. ㅠㅠ
751
18 câu hỏi đã được viết
강사님 일단
로그인안한 상태에서 /items에 접근하면
-> 이렇게 쿼리파라미터를 들고 login페이지로 새로 보여주는거까지는 잘됩니다.
-> 근데 여기서 /items로 redirect해줄려고
@RequestParam어노테이션을 사용해서 쿼리파라미터를 받아오려고 하면
이렇게 뜨거든요. 그래서 제가 컨트롤러 단에서 페이지를 다른 페이지로 돌리고 로그를 찍어보닌까 @RequestParam으로
redirectURL이라는 쿼리파라미터를 못불러 오는것 같습니다.
defalutURL을 넣어서 / 로 해주면 계속 /로가고
저걸 안넣어주면 쿼리파라미터를 찾을 수 없다고 에러가납니다.
이런 경우 어떻게 해결해야 할까요? 강의랑 특별히 다르게 한건 없는데;;;
Câu trả lời 3
2
서포터즈님!!!! 원인을 찾았습니다.
갑자기 오늘 집에서 나오다가 문뜩 타임리프 문법 배웠던게 생각나서 코드를보닌까
*loginForm.html
<form action="" th:action="@{/login}" th:object="${loginForm}" method="post">
<div th:if="${#fields.hasGlobalErrors()}">
<p class="field-error" th:each="err : ${#fields.globalErrors()}" th:text="${err}">전체 오류 메시지</p>
</div>
<div>
<label for="loginId">로그인 ID</label>
<input type="text" id="loginId" th:field="*{loginId}" class="form-control" th:errorclass="field-error">
<div class="field-error" th:errors="*{loginId}">
<p>계정 아이디 오류 메시지</p>
</div>
</div>
<div>
<label for="password">비밀번호</label>
<input type="password" id="password" th:field="*{password}" class="form-control" th:errorclass="field-error">
<div class="field-error" th:errors="*{password}">
<p>계정 비밀번호 오류 메시지</p>
</div>
</div>
<hr class="my-4">
<div class="row">
<div class="col">
<button class="w-100 btn btn-primary btn-lg" type="submit">로그인</button>
<button class="w-100 btn btn-secondary btn-lg"
onclick="location.href='items.html'"
th:onclick="|location.href='@{/}'|"
type="button">취소</button>
</div>
</div>
</form>
-> 이렇게 작성했었는데요
저번에 폼쪽 배울때 폼에 있는 th:action 쪽 url을 비워두면 현재 url로 간다는 말이 문뜩 생각이 났어요!!
<form action="" th:action th:object="${loginForm}" method="post">
<div th:if="${#fields.hasGlobalErrors()}">
<p class="field-error" th:each="err : ${#fields.globalErrors()}" th:text="${err}">전체 오류 메시지</p>
</div>
<div>
<label for="loginId">로그인 ID</label>
<input type="text" id="loginId" th:field="*{loginId}" class="form-control" th:errorclass="field-error">
<div class="field-error" th:errors="*{loginId}">
<p>계정 아이디 오류 메시지</p>
</div>
</div>
<div>
<label for="password">비밀번호</label>
<input type="password" id="password" th:field="*{password}" class="form-control" th:errorclass="field-error">
<div class="field-error" th:errors="*{password}">
<p>계정 비밀번호 오류 메시지</p>
</div>
</div>
<hr class="my-4">
<div class="row">
<div class="col">
<button class="w-100 btn btn-primary btn-lg" type="submit">로그인</button>
<button class="w-100 btn btn-secondary btn-lg"
onclick="location.href='items.html'"
th:onclick="|location.href='@{/}'|"
type="button">취소</button>
</div>
</div>
</form>
-> 이런식으로 비워두면 현재 url 경로로 간다는 말이 문뜩 생각나서 고치고 돌려보닌까 잘 동작합니다.
저 타임리프 용법이 이럴때 써먹는거였군요.... 아무 생각 없이 보기 좋으라고 다시 고쳐서 적어줬던 기억이 납니다....
이렇게 설계한 이유가 다 있었군요......................
0
해결 하셨다니 👍
배운 내용을 토대로 문제를 해결하면 그것만큼 짜릿한게 없죠..ㅎㅎ
네, action을 명시하지 않을 경우 해당 url의 get요청이 실행됩니다.
이미지 업로드와 db 트랜잭션 묶는법
0
42
1
Could not resolve org.springframework.boot:spring-boot-starter-validation:2.4.4
0
52
2
MessageSourceTest 코드
0
47
1
인터셉터 에러 설정
0
48
1
resolveArgument()메서드 질문
0
56
1
43강 검증1 에서 실패 로직 관련 질문있습니다.
0
54
2
타임리프 3.X 버전 rendering, serializer 에러 해결 방법
2
133
3
스프링 빈에 등록이 안되는거 같은데 어떻게 하면 좋을까요?ㅠㅠ
0
90
3
pdf 오타 문의
0
57
1
ItemUpdateForm 검증 관련 질문입니다.
0
48
1
22page 링크 주소 변경
0
59
2
특정 데이터와 파일을 함께 저장 시, 테이블 구조 질문
0
53
1
섹션3번 수업에 대한 질문입니다.
0
80
2
@Autowired 보다 더 좋은 방법이 어떤 걸까요?
0
85
2
타입컨버터 가 람다랑 비슷해 보이는데 저의 생각이 맞는지?.
0
65
1
자바스크립트 인라인에서 객체 직렬화 시 오류가 납니다
0
142
3
스프링부트 - 오류페이지2 에서 500.html 에서 쓰인 객체 질문
0
63
1
톰캣 에러 페이지가 안보입니다.
0
102
2
apiEceptionController에서 센드 에러 호출하면 안되는지?
0
81
1
세션 타임아웃시 쿠키 삭제 방법이 없나요?
0
118
2
ApiExceptionController 질문드립니다.
0
64
1
셀렉박스 챕터에서 option value에 ==배송 방식 선택== 이것을 넣은 이유가 궁금함, 이렇게 구상해도 되는지?
0
66
1
MemberRepository 필드의 fianl 선언 유무
0
85
2
혹시 index.html 에서는 fragment 사용이 안되는건가요
0
58
1

