package vo;
import java.sql.Connection;
import java.sql.DriverManager;
public class DBcon {
public static Connection getConnection() throws Exception {
String driver = "org.mariadb.jdbc.Driver";
String url = "jdbc:mariadb://localhost:3306/savedown";
Class.forName(driver);
Connection conn = DriverManager.getConnection(url,"root","1234");
return conn;
}
}
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ 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>
<script>
window.onload = function() {
const idcheck = document.querySelector("#idcheck");
let ids = document.querySelector("input[name=id]");
let idcheckdiv = document.querySelector("#idcheckdiv");
idcheck.addEventListener("click", check);
function check() {
if(ids.value =="흰둥이") {
alert("중복된 아이디");
}
}
}
</script>
</head>
<body>
<h1>회원가입페이지</h1>
<hr>
<div id=idcheckdiv></div>
<div>
<form action="0608registsucess.jsp" method="get">
아이디 <input type="text" name="id" placeholder="input id" required >
<button type="button" id="idcheck">중복확인</button>
<br>
비밀번호 <input type="password" name="pw" placeholder="input pw"required><br>
폰 번호 <input type="text" name="phoneNum" placeholder="input phoneNum"required><br>
<input type="submit" value="회원가입 하기">
</form>
</div>
</body>
</html>
<%@page import="vo.DBcon"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page import="vo.MemberVo2"%>
<%@ 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>
<%
String id = request.getParameter("id");
String pw = request.getParameter("pw");
String phone = request.getParameter("phoneNum");
//db안쓰고 할 때 application에 저장했다
application.setAttribute("ids", id);
application.setAttribute("pws" , pw);
String query = "INSERT INTO client (downfile,id,pw) VALUES (?,?,?)";
PreparedStatement stmt = DBcon.getConnection().prepareStatement(query);
stmt.setString(1, phone);
stmt.setString(2, id);
stmt.setString(3, pw);
stmt.executeUpdate();
%>
<h1>회원가입 성공</h1>
<a href ="0608loginpage.jsp">로그인페이지 가기</a>
</body>
</html>
<%@ 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>
<script>
</script>
</head>
<body>
<h1>로그인페이지</h1>
<hr>
<form action="0608logincheck.jsp" method="get">
아이디 <input type ="text" name="id" required>
비밀번호 <input type="password" name="pw" required>
<input type="submit" value="로그인">
</form>
</body>
</html>
<%@page import="vo.MemberVo2"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="vo.DBcon"%>
<%@page import="java.sql.Connection"%>
<%@ 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>
<%
String loginId = request.getParameter("id");
String loginPw = request.getParameter("pw");
//db안쓰고 할 때
String storeId =(String)application.getAttribute("ids");
String storePw =(String)application.getAttribute("pws");
Connection conn = DBcon.getConnection();
String query ="SELECT COUNT(*) FROM client where id=? AND pw=?";
PreparedStatement stmt = conn.prepareStatement(query);
stmt.setString(1, loginId);
stmt.setString(2, loginPw);
ResultSet rs = stmt.executeQuery();
rs.next();
int result = rs.getInt("count(*)");
if(result ==1) {
response.sendRedirect("0608loginsucesspage.jsp");
}else {
request.getRequestDispatcher("0608loginfailpage.jsp").forward(request, response);
//response.sendRedirect("0608loginfailpage.jsp");
}
%>
</body>
</html>
<%@ 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>
<h1>로그인성공!!!</h1>
</body>
</html>
<%@ 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>
<h1>로그인 실패</h1>
<a href="0608loginpage.jsp">로그인페이지가기</a>
</body>
</html>
'JSP > 연습' 카테고리의 다른 글
ajax로 배경색바꾸기 (0) | 2023.06.13 |
---|---|
배경화면 색 바꾸기 (0) | 2023.06.13 |
db연동해서 하기(SELECT, INSERT) (0) | 2023.06.08 |
JSP로 회원가입 폼 만들어보기 (0) | 2023.06.08 |
서블릿 + jsp파일로 시험문제 출제하기 (0) | 2023.06.07 |