login.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>로그인</title>
</head>
<body>
<hr width="300" size="2" color="red"/>
<h2 align="center">로그인</h2>
<hr width="300" size="2" color="red"/>
<form action="LoginOK" method="post">
<div align="center" style="width:500;">
<ul style="list-style:none;">
<li>아이디 <input type = "text" name = "id"/></li>
<li>비밀번호<input type="password" name = "pw"/></li>
<li><input type="submit" value = "로그인"/></li>
</ul>
</div>
</form>
</body>
</html>
------------------------------------------------------------------------------------------------------
LoginOK.java
package com.test.ex;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class LoginOK
*/
@WebServlet("/LoginOK")
public class LoginOK extends HttpServlet {
private static final long serialVersionUID = 1L;
private Connection dbconn;
private Statement stmt;
private ResultSet rs;
private String name, id, pw, hp ,hp2 ,hp3, gender;
/**
* @see HttpServlet#HttpServlet()
*/
public LoginOK() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("doGet");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("doPost");
loginDo(request, response);
}
private void loginDo(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException{
id=request.getParameter("id");
pw=request.getParameter("pw");
String sql = "select * from member where id = '"+id+"' and pw = '"+pw + "'";
try{
Class.forName("oracle.jdbc.driver.OracleDriver");
dbconn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "scott", "1234");
stmt=dbconn.createStatement();
//stmt.setString(1,name);
//stmt.setString(2,pw);
rs = stmt.executeQuery(sql);
while(rs.next()){
name=rs.getString("name");
id=rs.getString("id");
pw=rs.getString("pw");
hp=rs.getString("hp");
hp2=rs.getString("hp2");
hp3=rs.getString("hp3");
gender=rs.getString("gender");
}
HttpSession httpSession = request.getSession();
httpSession.setAttribute("name",name);
httpSession.setAttribute("id",id);
httpSession.setAttribute("pw",pw);
response.sendRedirect("loginRes.jsp");
}catch(Exception e){
e.printStackTrace();
}finally{
try{
if(stmt !=null) stmt.close();
if(dbconn !=null) dbconn.close();
}catch(Exception e){}
}
} //loginDo
}
----------------------------------------------------------------------------------------
loginRes.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%!
String name, id, pw;
%>
<!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=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
name=(String)session.getAttribute("name");
id=(String)session.getAttribute("id");
pw=(String)session.getAttribute("pw");
%>
<h2><%=name%>님 환영합니다.</h2>
<a href="modify.jsp">회원정보수정</a>
</body>
</html>
'기존카테고리 > JSP' 카테고리의 다른 글
리스트 출력 DTO,DAO,memberView.jsp (0) | 2017.06.07 |
---|---|
회원정보 수정 및 로그아웃 (0) | 2017.06.07 |
[회원가입] 회원가입 폼, 입력 (0) | 2017.06.07 |
[회원가입1]join.html, joinOK.java (0) | 2017.06.06 |
웹어플리케이션을 감시하는 리스너 ServletContextListener(contextInitialized(), contextDestroy()) (0) | 2017.06.06 |