본문 바로가기
JAVA & Spring

[JSP] 웹 쇼핑몰에 오신 것을 환영합니다. (+코드)

by 알기 쉬운 코딩 사전 2022. 12. 7.
반응형

welcome.jsp

<%@page import="java.util.Scanner"%>
<%@page import ="java.text.SimpleDateFormat"%>
<%@page import = "java.util.Date"%>
<%
	Date today = new Date();
	SimpleDateFormat format1 = new SimpleDateFormat("E M dd HH:mm:ss z yyyy");
%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<meta charset="UTF-8">
<title>JSP</title>
</head>
<body>
	<%@ include file="menu.jsp" %>

	<div class="container-fluid bg-secondary bg-opacity-25">
	<div class="p-5 mb-5">
				<h1 class="display-h1">웹 쇼핑몰에 오신 것을 환영합니다</h1>
	</div>
	</div>
	
	<main role = "main">
	
		<div class ="container">
			<div class ="text-center">
				<h3>
					Welcome to Web Market!
				</h3>
				현재 시간: 
				<%= format1.format(today) %>
			</div>
		</div>
	</main>
	</div>
	
	<%@ include file="footer.jsp" %>
	
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js">
</script>
</body>
</html>

 

menu.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

</head>
<body>
	<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
	  <div class="container-fluid">
		<a class="navbar-brand" a href="welcome.jsp">Home</a>
			<%@ include file="loginbutton.jsp" %>
	  </div>
	</nav>
</body>
</html>

 

loginbutton.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String uid = (String)session.getAttribute("id");
%>

<%
	if (uid == null) {
	%>
	<div>
		<a class="btn btn-secondary btn-lg" href="login2.html" role="button">Login</a>
	</div>

<%
	} else if (uid != null) {
	%>
	<div>
		<a class="btn btn-secondary btn-lg" href="logout.jsp" role="button">Logout</a>
	</div>
	<%};
	%>

 

login.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="utf-8"%>
<%

	String uid = request.getParameter("id");
	String ups = request.getParameter("ps");
	

	if ( uid == null ){
		out.println("로그인 정보가 없습니다.");
	}
	else  {
		session.setAttribute("id", uid);
		session.setAttribute("ps", ups);
		session.setMaxInactiveInterval(5);
		response.sendRedirect("welcome.jsp");
	}
%>

 

login2.html

<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<form action="login.jsp" method="post">
	</div>
		<table align=center>
		<tr><td colspan=2 align=center height=40><b><h1 class="display-1">Login</h1></b><td></tr>
		<tr>
		<td align=right>아이디&nbsp;</td>
		<td><input type="text" name="id" placeholder="Email address" required></td>
		</tr>
		<td align=right>패스워드&nbsp;</td>
		<td><input type="password" name="ps" required></td>
		</tr>
		<td colspan=2 align=center height=50>
		<input type="submit" value="Login">
		</td>
		</tr>
		</table>
	</form>
</body>
</html>

 

logout.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%
	session.invalidate();
	response.sendRedirect("welcome.jsp");
%>

 

footer.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<footer class="container">
		<p>&copy; WebMarket</p>
	</footer>
</body>
</html>
반응형

댓글