1. index.jsp
① session 값을 사용하는 방법
○ session값 가져오기
- 변수형 변수명 = (변수형)session.getAttribute("session에 올린 변수명")
- session에 올린 값은 변수형이 object이므로 다운캐스팅 해줘야한다.
- CustomInfo info = (CustomInfo)session.getAttribute("customInfo");
○ session 값 사용하기
방법 1 : ${info.userId }
CustomInfo info = (CustomInfo)session.getAttribute("CustomInfo"); 필요
방법 2 : ${sessionScope.customInfo.userId }
CustomInfo info = (CustomInfo)session.getAttribute("CustomInfo"); 필요X
sessionScope로 바로 불러서 사용하기 때문에
로그인O |
로그인 X |
○ 정보수정 / 로그아웃 ○ 성적처리(JSP) / 게시판 / 방명록 / 성적처리(Servlet) ○ 게시판(Servlet) - 글 작성 가능 |
○ 회원가입 / 로그인 ○ 게시판 열람만 가능 ○ 게시판 글 작성시 로그인 필요 |
${empty sessionScope.customInfo.userId } : session의 customInfo에서 userId의 값이 없으면(비어있으면) 실행
<body>
<c:choose>
<c:when test="${empty sessionScope.customInfo.userId }">
<a href="<%=cp%>/join/created.do" style="text-decoration: none">회원가입</a>
<a href="<%=cp%>/join/login.do" style="text-decoration: none">로그인</a><br/><br/>
</c:when>
<c:otherwise>
<a href="<%=cp%>/join/updated.do" style="text-decoration: none">정보수정</a>
<a href="<%=cp%>/join/logout.do" style="text-decoration: none">로그아웃</a><br/><br/>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${empty sessionScope.customInfo.userId }">
<b>로그인 하면 새로운 세상이 보입니다...</b><br/><br/>
</c:when>
<c:otherwise>
${sessionScope.customInfo.userName }님 반갑습니다:)<br/><br/>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${empty sessionScope.customInfo.userId }">
1.성적처리(JSP)<br/>
2.게시판<br/>
3.방명록<br/>
4.성적처리(Servlet)<br/>
</c:when>
<c:otherwise>
1.<a href="<%=cp%>/score/list.jsp" style="text-decoration: none">성적처리(JSP)</a><br/>
2.<a href="<%=cp%>/board/list.jsp" style="text-decoration: none">게시판</a><br/>
3.<a href="<%=cp%>/guest/guest.jsp" style="text-decoration: none">방명록</a><br/>
4.<a href="<%=cp%>/sung/list.do" style="text-decoration: none">성적처리(Servlet)</a><br/>
</c:otherwise>
</c:choose>
5.<a href="<%=cp%>/bbs/list.do" style="text-decoration: none">게시판(Servlet)</a><br/>
</body>
결과
○ index.jsp(초기화면) - 로그인X
○ index.jsp(초기화면) - 로그인O
○ 회원가입
○ 로그인
○ 정보수정
○ 1.성적처리(JSP)
○ 2.게시판
○ 3.방명록
○ 4.성적처리(Servlet)
○ 5.게시판(Servlet)
'STUDY > JSP' 카테고리의 다른 글
쿠키(cookie) (0) | 2019.02.28 |
---|---|
회원가입(서블릿) - 정보수정, 게시판 (0) | 2019.02.27 |
회원가입(서블릿) - 회원가입, 로그인, 비밀번호 찾기, 로그아웃 (2) | 2019.02.26 |
회원가입(서블릿) - DB, DAO, DTO (0) | 2019.02.26 |
게시판(서블릿) - 코드 (0) | 2019.02.26 |
댓글