강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

with_all님의 프로필 이미지
with_all

작성한 질문수

스프링 MVC 2편 - 백엔드 웹 개발 활용 기술

HTML에서의 URL에 관한 질문 (2)

작성

·

185

0

안녕하세요. 앞선 질문에 대한 답변 감사드립니다. 제가 이해가 부족하여 착오가 있었던 것 같습니다.

그런데 아래 코드에서 <form action="item.html" th:action th:object="${loginForm}" method="post">

이 form이 전송되어야 할 주소 /login은 thymeleaf에 기술되어 있지 않은데, 어떻게 form의 데이터가 /login으로 전송되는 것일까요?

<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <link th:href="@{/css/bootstrap.min.css}"
          href="../css/bootstrap.min.css" rel="stylesheet">
    <style>
        .container {
            max-width: 560px;
        }
        .field-error {
            border-color: #dc3545;
            color: #dc3545;
        }
    </style>
</head>
<body>

<div class="container">

    <div class="py-5 text-center">
        <h2>로그인</h2>
    </div>

    <form action="item.html" 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}" />
        </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}" />
        </div>

        <hr class="my-4">

        <div class="row">
            <div class="col">
                <button class="w-100 btn btn-primary btn-lg" type="submit">로그인</button>
            </div>
            <div class="col">
                <button class="w-100 btn btn-secondary btn-lg" onclick="location.href='items.html'"
                        th:onclick="|location.href='@{/}'|"
                        type="button">취소</button>
            </div>
        </div>

    </form>

</div> <!-- /container -->
</body>
</html>

답변 1

0

안녕하세요. with_all님, 공식 서포터즈 David입니다.
.

아래 글 답변 확인해주세요.
https://www.inflearn.com/questions/383967
.
감사합니다.

with_all님의 프로필 이미지
with_all
질문자

답변 감사합니다.

with_all님의 프로필 이미지
with_all

작성한 질문수

질문하기