카테고리 없음
LOGIN ( 분 )
Binsoo
2020. 8. 18. 16:27
728x90
반응형
login.jap
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<html>
<head>
<title>[login.jsp]</title>
<style type="text/css">
input, b{font-size: 20pt; font-weight: bold;}
a{text-decoration: none;font-size: 20pt; font-weight: bold;}
a:hover {color: red; font-size: 20pt; font-weight: bold;}
#LOG-IN{
font-size:26pt; font-weight: bold;
background:"green"; height:120;
}
</style>
<script type="text/javascript">
var xhr; //전역변수
function first( ){
return new XMLHttpRequest( );
}//end
function two(){
var a=document.getElementById("userid").value; //myform.userid.value;
var b=document.getElementById("pwd").value; //myform.pwd.value;
var url="loginSave.jsp?UID="+a+"&UPWD="+b;
//var url="loginList.jsp?UID="+a+"&UPWD="+b;
//var url="login.tis?UID="+a+"&UPWD="+b;
alert("url = "+url);
xhr=first();
xhr.onreadystatechange=display;
xhr.open("GET", url, true);
xhr.send();
}//end
function display( ){
if(xhr.readyState==4){
if(xhr.status==200){
var message=xhr.responseText;
document.getElementById("msg").innerHTML=message;
}//200 end
}//4 end
}//end
</script>
</head>
<body>
<div id="msg" align="center">
<table width="550" border="1" cellspacing="0">
<form name="myform">
<tr>
<td width=350> <b>userid: </b></td>
<td> <input type="text" name="userid" id="userid" value="sky"></td>
<td rowspan=2 align="center">
<input type="button" onclick="two( )" value="LOG-IN" id="LOG-IN" >
</td>
</tr>
<tr>
<td width=350><b>userpw: </b> </td>
<td>
<input type="text" name="pwd" id="pwd" value="1234">
</td>
</tr>
</form>
</table>
</div>
</body>
</html>
loginJQueryAjax.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<html>
<head>
<title>[loginjQueryAjax.jsp]</title>
<style type="text/css">
input, b{font-size: 20pt; font-weight: bold;}
a{text-decoration: none;font-size: 20pt; font-weight: bold;}
a:hover {color: red; font-size: 20pt; font-weight: bold;}
#btnlogin{
font-size:26pt; font-weight: bold;
background:"pink"; height:120;
}
#loading-mask{
display:none;
width:500px;
height:500px;
}
</style>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(function( ){
$('#btnlogin').click( function( ){
$.ajax({
"url" : "loginSave.jsp" ,
"type" : "get",
"data" : {UID: $('#userid').val(), UPWD: $('#pwd').val( )} ,
"beforeSend": function( ){
$('#loading-mask').show();
$('#msgIN').empty();
$('#loading-mask').html("<div align=center><img src='./images/ajax-loader.gif' width=500 height=250></div> ");
$("#loading-mask").css("opacity","0.9").stop().animate({opacity:3},9000);
},
"success": function(data){
setTimeout(function() {
$('#loading-mask').fadeOut( );
$('#msgIN').empty();
$('#msg').html(data);
}, 1000);
},
"error": function(data){$('#loading-mask').fadeOut(); }
});
});
//////////////////////////////////////////////////////////////////////////
});
</script>
</head>
<body>
<div id="msg" align="center">
<div id="msgIN">
<table width="550" border="1" cellspacing="0">
<form name="myform" method="get">
<tr>
<td width=350> <b>userid: </b></td>
<td> <input type="text" name="userid" id="userid" value="sky"></td>
<td rowspan=2 align="center">
<input type="button" id="btnlogin" value="loginAjax" >
</td>
</tr>
<tr>
<td width=350><b>userpw: </b> </td>
<td>
<input type="text" name="pwd" id="pwd" value="1234">
</td>
</tr>
</form>
</table>
</div>
<div id="loading-mask"> </div>
</div>
</body>
</html>
loginList.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file="ssi.jsp" %>
<!DOCTYPE html>
<html> <head>
<title> [loginList.jsp]</title>
<style type="text/css">
*{font-size:14pt; font-weight:bold; font-family: Comic Sans MS ; margin-left: 10px; }
a{font-size:14pt; text-decoration:none; font-weight:bold; color:blue; font-family: Comic Sans MS ; }
a:hover{font-size:16pt; text-decoration:underline; color:green; font-family: Comic Sans MS ; }
</style>
</head>
<body>
<p><br>
<div align="center">
<img src="images/a1.png">
</div>
<%
//loginList.jsp
String a = request.getParameter("UID");
String b = request.getParameter("UPWD");
try{
msg="select count(*) as cnt from login where userid =? and pwd =? ";
PST=CN.prepareStatement(msg);
PST.setString(1, a);
PST.setString(2, b);
RS=PST.executeQuery();
}catch(Exception ex){ System.out.println(ex); }
if(RS.next()==true){ Gtotal=RS.getInt("cnt"); }
if( Gtotal>0){
session.setAttribute("naver", a); //userid값을 가짜변수 naver에 넘김
response.sendRedirect("guestList.jsp");
//Cookie ck=new Cookie("google", a); //쿠키내장클래스 객체화
//response.addCookie(ck); //쿠키추가등록
//response.sendRedirect("main.jsp");
}else{
%>
<script type="text/javascript">
alert("로그인문서로 이동합니다\UserID,PWD데이터를 입력하세요");
location.href="login.jsp";
</script>
<%}%>
</body>
</html>
loginSave.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<%@ include file="ssi.jsp" %>
<html>
<head><title> [loginSave.jsp] </title></head>
<body>
<%
String usera=request.getParameter("UID");
String userb=request.getParameter("UPWD");
msg="select count(*) as cnt from login where userid=? and pwd=? ";
System.out.println( "loginSave.jsp " + msg);
PST=CN.prepareStatement(msg);
PST.setString(1, usera);
PST.setString(2, userb);
RS=PST.executeQuery();
RS.next(); Gtotal=RS.getInt("cnt");
if(Gtotal>0){
%>
<font size=7 color=blue>
<b><%= usera %>님 로그인 성공!!!</b> <br>
</font><p>
<img src="images/bt_login.gif" width=450 height=70><p>
<img src="images/bar.gif" width=450 >
<%
}else{
//response.sendRedirect("login.jsp");
out.println("<font size=7 color=red><b></b>"+usera+"님 로그인실패</font><p>");
out.println("<font size=7><a href='login.jsp'>[로그인]</a></font>");
out.println("<font size=7><a href='index.jsp'>[index]</a></font>");
}
%>
</body>
</html>
728x90
반응형