ㅋㅋㅋㅋ 좋아! 드디어 진짜 재밌는 걸 건드렸다.
"익명 방명록" 만들어줄게. 이름 없이 그냥 글만 남기고, 바로 아래에 다른 사람들이 쓴 것도 실시간으로 쭉 출력되는 구조야.
누가 썼는지 모르니까 익명으로 막 쏟아내도 괜찮지… 🤭
anonymousGuestbook.jsp
(익명 방명록 JSP)<%@ page import="java.util.*" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
request.setCharacterEncoding("UTF-8");
// application 영역에 방명록 리스트가 없으면 새로 생성
List<String> guestbook = (List<String>) application.getAttribute("guestbook");
if (guestbook == null) {
guestbook = new ArrayList<>();
application.setAttribute("guestbook", guestbook);
}
// 메시지 입력값 받기
String newMsg = request.getParameter("message");
if (newMsg != null && !newMsg.trim().equals("")) {
// 메시지 추가 (가장 아래에 추가되게 순서 유지)
guestbook.add(newMsg.trim());
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>📝 익명 방명록</title>
</head>
<body>
<h1>😈 즉석 익명 방명록</h1>
<form method="post">
<textarea name="message" rows="4" cols="50" placeholder="하고 싶은 말 막 써봐요..."></textarea><br>
<button type="submit">익명으로 남기기</button>
</form>
<hr>
<h3>💬 지금까지 남긴 말들:</h3>
<ul>
<%
for (String msg : guestbook) {
%>
<li><%= msg %></li>
<%
}
%>
</ul>
<p><a href="resetGuestbook.jsp">🧹 전체 삭제 (관리자용)</a></p>
</body>
</html>
resetGuestbook.jsp
(전체 삭제용)<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
application.removeAttribute("guestbook");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>방명록 초기화</title>
</head>
<body>
<h2>🧹 익명 방명록 초기화 완료!</h2>
<a href="anonymousGuestbook.jsp">⏪ 돌아가기</a>
</body>
</html>
application
영역이라 모든 사용자에게 공유resetGuestbook.jsp
로 전체 삭제 가능 (혼자 관리도 가능)글번호
붙이기남긴 시각
저장해서 함께 보여주기bad word filter
(금칙어 차단: 욕설 탐지)글자 수 제한
또는 최근 10개만 보여주기
만족해? 더 업그레이드할까?
너만의 짧고 센 말 남기는 공간 지금 열렸어 😆