Skip to content

4주차 미션 / 서버 5조 유찬영#3

Open
holdn2 wants to merge 5 commits intoKonkuk-KUIT:mainfrom
holdn2:uchan0-week4
Open

4주차 미션 / 서버 5조 유찬영#3
holdn2 wants to merge 5 commits intoKonkuk-KUIT:mainfrom
holdn2:uchan0-week4

Conversation

@holdn2
Copy link
Copy Markdown

@holdn2 holdn2 commented Apr 9, 2025

4주차 미션 진행했습니다.
2단계를 진행할 때 요구사항을 제대로 반영했는지 피드백해주시면 감사드리겠습니다.
뷰에 직접 접근하게 하면 안된다는 뜻이 url에 .jsp가 붙지 않도록 하면 된다고 이해해서 반영해봤습니다.

Copy link
Copy Markdown
Contributor

@kisusu115 kisusu115 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드 전체적으로 잘 보았습니다!
요구사항에 나온 세부적인 사항까지 신경써서 진행해주셔서 너무 좋았던 것 같습니다.

뷰에 직접 접근하게 하면 안된다는 뜻은 이해하신 내용이 맞습니다. 추가적으로 설명을 붙이면, 해당 파일이 위치하는 경로를 클라이언트가 알지 못하게하는 의도라고 생각합니다.

클라이언트가 특정 파일의 경로를 알게되고, 만약 직접적으로 접근이 가능하도록 열어둔다면 인증/인가 없이도 접근하는 등 보안적으로 허점이 생길 것 같습니다. 중간에 요청을 처리하는 컨트롤러를 둠으로서 요청에 대해 서버에서 제어할 수 있도록 되는 것이죠 이건 역할 분리 측면에서도 필요하다고 생각합니다.

추가적으로 jsp는 HTML을 생성하는 템플릿 역할을 하고 있기에, 해당 파일의 정보 자체를 클라이언트에게 전달하는 것은 좋지 않다고 생각합니다.

예시 코드 참고하시면서 추가적인 의문점을 풀어나가셨으면 좋겠습니다!


// 없을 시 404 에러 후 return
if (controller == null) {
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요구사항에 없었는데도 404 처리 해주신 것 너무 좋습니다!

</c:when>
<c:otherwise>
<a href="/user/loginForm" type="button" class="btn btn-outline-primary me-2">Log-In</a>
<a href="/user/signupForm" type="button" class="btn btn-primary">Sign-up</a>
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url에서 jsp 모두 감춰주신 것 너무 좋습니다.

// redirect 시 변환한다.
String pageName = controller.execute(req,resp);
if (pageName.startsWith("redirect:")) {
resp.sendRedirect(pageName.substring("redirect:".length()));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"redirect:"가 특정한 목적을 가진 문자열인 만큼 상수로 정의한다면 더 좋을 것 같습니다!

// 로그인 안 되어 있으면 로그인 페이지로 리다이렉트
// sendRedirect는 get요청으로 하는 것임. 따라서 doPost만 구현되어있는 컨트롤러로는 보낼 수 없음.
// doGet이 되어있으면 가능하지만 doPost만 되어있으면 sendRedirect 못씀. forward를 써야함.
return "redirect:/user/loginForm";
Copy link
Copy Markdown
Contributor

@kisusu115 kisusu115 Apr 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 컨트롤러에 해당하는 사항은 아니지만, POST->POST 방식으로 메소드 및 요청 정보를 유지하여 리다이렉트 시키는 경우도 있습니다! HTTP 상태코드 301, 302와 307, 308의 차이를 찾아보시면 좋을 것 같아요.

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginFormController implements Controller {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CreateUserFormController / LoginFailedFormController / LoginFormController
이렇게 3개의 컨트롤러는 중간 처리없이 단순히 파일 정보를 반환하는 공통된 로직을 가지고 있기에, 묶어서 일괄적으로 처리해도 좋을 것 같습니다! 예시 코드의 ForwardController를 참고하시면 좋을 것 같아요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants