728x90
2021/04/14(수)
JSP 회원가입 알고리즘 참조
https://cordingdoah.tistory.com/103
<python_mypageProcess.jsp>
- 메인에서 mypage클릭 시 이동됌
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%@ include file="python_conn.jsp" %>
<%
String mem_id = (String) session.getAttribute("mem_id");
String mem_pass = (String) session.getAttribute("mem_pass");
if(mem_id =="undefined" || mem_id ==null || mem_id ==""){
out.println("<script>alert('Please log in'); history.back();</script>");
return;
}
%>
<%
ResultSet rs = null;
Statement stmt = conn.createStatement();
String sql ="SELECT * FROM member WHERE mem_id = '" + mem_id +"' ";
rs = stmt.executeQuery(sql);
String mem_id2="";
String mem_name2="";
String mem_location2="";
String mem_hint2="";
String mem_aws2="";
String mem_pw="";
while(rs.next()){
mem_id2 = rs.getString("mem_id");
mem_name2 = rs.getString("mem_name");
mem_location2 = rs.getString("mem_location");
mem_hint2 = rs.getString("mem_hint");
mem_aws2 = rs.getString("mem_aws");
mem_pw = rs.getString("mem_pw");
}
session.setAttribute("mem_id2", mem_id2);
session.setAttribute("mem_name2", mem_name2);
session.setAttribute("mem_location2", mem_location2);
session.setAttribute("mem_hint2", mem_hint2);
session.setAttribute("mem_aws2", mem_aws2);
session.setAttribute("mem_pw", mem_pw);
//RequestDispatcher rd = request.getRequestDispatcher("Mini_MainDP.jsp");
//rd.forward(request,response);
pageContext.forward("python_mypage.jsp");
%>
</body>
</html>
메인페이지에서 로그인을 하고 mypage 클릭시 주소창으로 id와 password값을 넘겨줌
1. 주소창에 있는 id, pw 값을 가져옴 만약 받아온 값이 없을 경우 로그인이 되지 않은 것이기 때문에 팝업창 출력
2. 로그인되어 있는 상태라면 id값을 이용해서 db에서 조회
3. 값들을 변수에 저장 하고 세션으로 값을 넘겨줌
4. 마이페이지 화면을 보여주는 python_mypage.jsp 이동
--> 결과화면
<python_mypage.jsp>
<!DOCTYPE HTML>
<!--
Traveler by freehtml5.co
Twitter: http://twitter.com/fh5co
URL: http://freehtml5.co
-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Traveler — Free Website Template, Free HTML5 Template by FreeHTML5.co</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Free HTML5 Website Template by FreeHTML5.co" />
<meta name="keywords" content="free website templates, free html5, free template, free bootstrap, free website template, html5, css3, mobile first, responsive" />
<meta name="author" content="FreeHTML5.co" />
<!-- Facebook and Twitter integration -->
<meta property="og:title" content=""/>
<meta property="og:image" content=""/>
<meta property="og:url" content=""/>
<meta property="og:site_name" content=""/>
<meta property="og:description" content=""/>
<meta name="twitter:title" content="" />
<meta name="twitter:image" content="" />
<meta name="twitter:url" content="" />
<meta name="twitter:card" content="" />
<link href="https://fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet">
<!-- Animate.css -->
<link rel="stylesheet" href="css/animate.css">
<!-- Icomoon Icon Fonts-->
<link rel="stylesheet" href="css/icomoon.css">
<!-- Themify Icons-->
<link rel="stylesheet" href="css/themify-icons.css">
<!-- Bootstrap -->
<link rel="stylesheet" href="css/bootstrap.css">
<!-- Magnific Popup -->
<link rel="stylesheet" href="css/magnific-popup.css">
<!-- Magnific Popup -->
<link rel="stylesheet" href="css/bootstrap-datepicker.min.css">
<!-- Owl Carousel -->
<link rel="stylesheet" href="css/owl.carousel.min.css">
<link rel="stylesheet" href="css/owl.theme.default.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="css/style.css">
<!-- Modernizr JS -->
<script src="js/modernizr-2.6.2.min.js"></script>
<!-- FOR IE9 below -->
<!--[if lt IE 9]>
<script src="js/respond.min.js"></script>
<![endif]-->
<style>
.login-center{
position: absolute;
min-height: 1px;
padding-left: 15px;
padding-right: 15px;
width: 400px;
height: 600px;
left: 35%;
top: 50%;
transform:translateX(-50%);
}
</style>
<%
String mem_id2 = (String) session.getAttribute("mem_id2");
String mem_name2 = (String) session.getAttribute("mem_name2");
String mem_location2 = (String) session.getAttribute("mem_location2");
String mem_hint2 = (String) session.getAttribute("mem_hint2");
String mem_aws2 = (String) session.getAttribute("mem_aws2");
String mem_pw2 = (String) session.getAttribute("mem_pw");
if(mem_id2 =="undefined" || mem_id2 ==null || mem_id2 ==""){
out.println("<script>alert('Please log in'); history.back();</script>");
return;
}
%>
</head>
<body>
<div class="gtco-loader"></div>
<div id="page">
<!-- <div class="page-inner"> -->
<nav class="gtco-nav" role="navigation">
<div class="gtco-container">
<div class="row">
<div class="col-sm-4 col-xs-12">
<div id="gtco-logo"><a href="python_MainDP.jsp">RESTAURANT FINDER<em>.</em></a></div>
</div>
<div class="col-xs-8 text-right menu-1">
<ul>
<li><a href="#">Pricing</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div>
</div>
</nav>
<header id="gtco-header" class="gtco-cover gtco-cover-md" role="banner" style="background-image: url(images/change-3.jpg)">
<div class="overlay"></div>
<div class="gtco-container">
<div class="row">
<div class="col-md-12 col-md-offset-0 text-left">
<div class="row row-mt-15em">
<div class="login-center col-md-push-1 animate-box" data-animate-effect="fadeInRight">
<div class="form-wrap">
<div class="tab">
<div class="tab-content">
<div class="tab-content-inner active" data-content="signup">
<h3>MY PAGE</h3>
<form action="python_mypage2.jsp">
<div class="row form-group">
<div class="col-md-12">
<label for="fullname">ID</label>
<input type="text" id="mem_id" name="mem_id" value="" class="form-control">
</div>
<div class="col-md-12">
<label for="fullname">Name</label>
<input type="text" id="mem_name" name="mem_name" value="" class="form-control">
</div>
<div class="col-md-12">
<label for="fullname">Location</label>
<input type="text" id="mem_location" name="mem_location" value="" class="form-control">
</div>
<div class="col-md-12">
<label for="activities">Password Hint</label>
<select name="mem_hint" id="mem_hint" class="form-control">
<option value="Where were you born?">Where were you born?</option>
<option value="What is your hobby">What is your hobby</option>
<option value="What is the name of the elementary school you attended?">What is the name of the elementary school you attended?</option>
<option value="What is your number one treasure?">What is your number one treasure?</option>
</select>
</div>
<div class="col-md-12">
<label for="fullname">Answer</label>
<input type="text" id="mem_aws" name="mem_aws" value="" class="form-control">
</div>
<div class="col-md-12">
<label for="fullname">Password</label>
<input type="password" id="mem_pw1" name="mem_pw1" value="" class="form-control">
</div>
<div class="col-md-12">
<label for="fullname">Password Check</label>
<input type="password" id="mem_pw2" name="mem_pw2" value="" class="form-control">
</div>
<div class="col-md-12">
<br><input type="submit" class="btn btn-primary btn-block" value="confirm">
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</header>
<!-- </div> -->
</div>
<div class="gototop js-top">
<a href="#" class="js-gotop"><i class="icon-arrow-up"></i></a>
</div>
<!-- jQuery -->
<script src="js/jquery.min.js"></script>
<!-- jQuery Easing -->
<script src="js/jquery.easing.1.3.js"></script>
<!-- Bootstrap -->
<script src="js/bootstrap.min.js"></script>
<!-- Waypoints -->
<script src="js/jquery.waypoints.min.js"></script>
<!-- Carousel -->
<script src="js/owl.carousel.min.js"></script>
<!-- countTo -->
<script src="js/jquery.countTo.js"></script>
<!-- Stellar Parallax -->
<script src="js/jquery.stellar.min.js"></script>
<!-- Magnific Popup -->
<script src="js/jquery.magnific-popup.min.js"></script>
<script src="js/magnific-popup-options.js"></script>
<!-- Datepicker -->
<script src="js/bootstrap-datepicker.min.js"></script>
<!-- Main -->
<script src="js/main.js"></script>
<script type="text/javascript">
document.getElementById("mem_id").value = <%= mem_id2%>
document.getElementById("mem_name").value = <%= mem_name2%>
document.getElementById("mem_location").value = <%= mem_location2%>
$("#mem_hint").val("<%=mem_hint2%>").prop("selected",true);
document.getElementById("mem_aws").value = <%= mem_aws2%>
document.getElementById("mem_pw1").value = <%= mem_pw2%>
document.getElementById("mem_pw2").value = <%= mem_pw2%>
//document.getElementById('mem_id').disabled = true;
</script>
</body>
</html>
1. 받아온 값들을 java 변수에 저장하고 화면상에 띄워줌
2. 값을 변경하고 확인버튼 클릭 시 python_mypage2.jsp로 이동
--> 결과화면
<python_mypage2.jsp>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%@ include file="python_conn.jsp" %>
<%
String mem_id = request.getParameter("mem_id");
String mem_name = request.getParameter("mem_name");
String mem_location = request.getParameter("mem_location");
String mem_hint = request.getParameter("mem_hint");
String mem_aws = request.getParameter("mem_aws");
String mem_pw1 = request.getParameter("mem_pw1");
String mem_pw2 = request.getParameter("mem_pw2");
ResultSet rs = null;
Statement stmt = conn.createStatement();
String sql ="UPDATE member SET mem_name = '" + mem_name +"' ,";
sql += "mem_location = '" + mem_location + "', mem_hint= '" + mem_hint + "', ";
sql += "mem_aws = '" + mem_aws + "', mem_pw= '" + mem_pw1 +"' ";
sql += "WHERE mem_id= '" + mem_id +"'";
//rs = stmt.executeQuery(sql);
if(mem_name.trim().equals(""))
out.println("<script>alert('이름을 입력해주세요.'); history.back();</script>");
else if(mem_location.trim().equals(""))
out.println("<script>alert('사는 지역을 입력해주세요'); history.back();</script>");
else if(mem_aws.trim().equals(""))
out.println("<script>alert('비밀번호 답을 입력해주세요(비밀번호 찾을 시 필요)'); history.back();</script>");
else if(mem_pw1.trim().equals(""))
out.println("<script>alert('비밀번호를 입력해주세요.'); history.back();</script>");
else if(mem_pw2.trim().equals(""))
out.println("<script>alert('비밀번호 확인를 입력해주세요.'); history.back();</script>");
else if(mem_pw1.equals(mem_pw2)){
stmt.executeUpdate(sql);
out.println("<script>alert('변경완료');history.go(-2)</script>");
}
else
out.println("<script>alert('비밀번호가 일치하지 않습니다.'); history.back();</script>");
%>
</body>
</html>
1. 내 정보를 수정할 시 이름, 지역, 비민번호 답, 비밀번호, 비밀번호 확인 모두 빈칸이 아니고 비밀번호가 일치하면 변경완료 출력
--> 결과화면
변경완료 후 mypage
728x90
'코딩 연습장 > JSP' 카테고리의 다른 글
Python/JSP/R 이용한 맛집 프로젝트 - 11 (JSP, DB 연동) (0) | 2021.06.21 |
---|---|
Python/JSP/R 이용한 맛집 프로젝트 - 9 (JSP 지역별 지도화면) (0) | 2021.06.19 |
Python/JSP/R 이용한 맛집 프로젝트 - 7 (JSP 회원가입) (0) | 2021.06.19 |
Python/JSP/R 이용한 맛집 프로젝트 - 6 (JSP 아이디, 비밀번호 찾기) (0) | 2021.06.19 |
Python/JSP/R 이용한 맛집 프로젝트 - 5 (JSP 로그인) (0) | 2021.06.19 |