웹개발 교육/jsp

[57일] jsp (28) - myweb 프로젝트(회원 등급 별 권한 부여)

ewok 2022. 10. 18. 11:58

게시판 등을 사용하다 보면 등급별로 기능에 대한 권한 부여가 다른 경우를 볼 수 있다.

예를 들면 글 작성은 누구나 할 수 있지만, 글 삭제는 글쓴이와 관리자가 아니면 삭제할 수 없는 경우이다.

 

bbsRead.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="ssi.jsp"%>
<%@ include file="../member/auth.jsp"%>
<%@ include file="../header.jsp"%>
<!-- 본문 시작 bbsRead.jsp-->
<h3>*게시판 상세보기 *</h3>
<p>
	<a href="bbsForm.jsp">[글쓰기]</a>
	&nbsp;&nbsp;
	<a href="bbsList.jsp?col=<%=col%>&word=<%=word%>&nowPage=<%=nowPage%>">[글목록]</a>
</p>
<div class="container">
<%
	int bbsno = Integer.parseInt(request.getParameter("bbsno"));
	dto = dao.read(bbsno);
	if(dto==null){
		out.print("해당 글 없음!!");
	} else {
		dao.incrementCnt(bbsno); //조회수 증가
%>
		<table class="table">
		<tr>
			<th class="success">제목</th>
			<td><%=dto.getSubject()%></td>
		</tr>
		<tr>
			<th class="success">내용</th>
			<td style="text-align: left">
<%
				//특수문자로 치환하기
				//사용자가 입력한 엔터를 <br>태그로 바꾸기
				String content = Utility.convertChar(dto.getContent());
				out.print(content);
%>			
			</td>
		</tr>		
		<tr>
			<th class="success">조회수</th>
			<td><%=dto.getReadcnt()%></td>
		</tr>
		<tr>
			<th class="success">작성자</th>
			<td><%=dto.getWname()%></td>
		</tr>
		<tr>
			<th class="success">작성일</th>
			<td><%=dto.getRegdt()%></td>
		</tr>
		<tr>
			<th class="success">IP</th>
			<td><%=dto.getIp()%></td>
		</tr>								
		</table>
		<br>
		<input type="button" value="답변쓰기" class="btn btn-info" onclick="location.href='bbsReply.jsp?bbsno=<%=bbsno%>'">
		<input type="button" value="수정" class="btn btn-warning" onclick="location.href='bbsUpdate.jsp?bbsno=<%=bbsno%>&col=<%=col%>&word=<%=word%>'">
<%		if(s_mlevel.equals("A1")){ %>
		<input type="button" value="삭제" class="btn btn-danger" onclick="location.href='bbsDel.jsp?bbsno=<%=bbsno%>'">
<%		}//if end		
	}//if end
%>
</div>

<!-- 본문 끝 -->
<%@ include file="../footer.jsp"%>

 

위와 같이 삭제가 있는 태그에 조건문을 사용하여 A1등급인 사용자만 삭제 버튼을 볼 수 있도록 하였다.

 

A1 등급
D1 등급