package com.shop.model;

import java.sql.*;

import javax.sql.*;
import javax.naming.*;

public class joinDAO {
 public Connection dbCon(){
  //Tomcat Context로 부터 jdbc/oracle이름의 DataSource를 가져와서
  //DB Connection객체를 생성해서 리턴
  //이 작업을 반복해서 하지 않도록 메서드로 작성.
  Connection con = null;
  try{
   Context ctx = new InitialContext();
   Context tomcat = (Context)ctx.lookup("java:comp/env");
   DataSource ds = (DataSource)tomcat.lookup("jdbc/oracle");
   con = ds.getConnection(); 
  }catch(Exception e){
   e.printStackTrace();
  }
  return con;
 }//dbCon end
 
 public void dbClose(Connection con, Statement stat, ResultSet rs){
  try{
   if(con!=null) con.close();
   if(stat!=null) stat.close();
   if(rs!=null) rs.close();
  }catch(Exception e){
   e.printStackTrace();   
  }
 }//dbClose end
 
 public boolean dupIdCheck(String uid){ //중복 ID체크 수행 메서드
  boolean success = false;
  Connection con = null;
  PreparedStatement stat = null;
  ResultSet rs = null;
  String sql = "select * from userinfo where userid = ? ";
  try{
   con = dbCon();
   stat = con.prepareStatement(sql);
   stat.setString(1, uid);
   rs = stat.executeQuery();
   while(rs.next()){
    if(rs.getString("userid").length() > 0) success = true;   
   }//while end
  }catch(Exception e){
   e.printStackTrace();   
  }finally{
   dbClose(con,stat,rs);
  }
  return success;
 }//dupIdCheck() end
 
 public UserVo joinProc(UserVo user){ //회원가입 처리 메서드
  UserVo vo = null;
  return vo;
 }//joinProc() end
}

'2020년도 이전 > temp' 카테고리의 다른 글

안드로이드 8월 13일 xml  (0) 2013.08.13
joinProcessServlet.java  (0) 2013.08.01
join_confirm --- 수정중!!  (0) 2013.07.31
서블릿 -- LoginServlet.java  (0) 2013.07.31
회원가입 디비 연결하자~~~ LoginDAO  (0) 2013.07.31

<%@page import="java.io.*"%>
<%@page import="java.net.URL"%>

<%@ page contentType="text/html; charset=utf-8"%>
<!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>ServletContext를 이용한 자원 읽기1</title>
</head>
<body>
 <h3>ServletContext를 이용한 자원 읽기1</h3>
 <hr>
 <%-- ServletContext타입의 jsp내장객체명은 application
ServletContext 객체를 사용해서 웹 컨텍스트 아래 파일 자원 내용 읽어오기 --%>

 소스참조.txt의 실제경로 :
 <%=application.getRealPath("/소스참조.txt")%><br> 소스참조.txt의 내용 :
 <br>

 <%
  FileReader fr = null;
  char[] buff = new char[512];
  int len = -1;
  BufferedReader br = null;
  InputStreamReader isr = null;
  try {
   /* fr = new FileReader(application.getRealPath("/소스참조.txt"));
   while( (len = fr.read(buff)) != -1 ){
    out.println(new String(buff, 0, len)); 
   } */
   isr = new InputStreamReader(new FileInputStream(application.getRealPath("/소스참조.txt")));
   br = new BufferedReader(isr);
   String st = null;
   while ((st = br.readLine()) != null) {
    out.println(st + "<br>");
   }

  } catch (Exception e) {
   e.printStackTrace();
  } finally {
   try {
    if (fr != null)
     fr.close();
   } catch (Exception e) {
    e.printStackTrace();
   }
  }
 %>
</body>
</html>

 

 

-----------------------------  요렇게로도 할 수 있어요!!!--------------------------

 

위 소스에서 변경된 부분에 컬러 넣었어요~~~~

<%@page import="java.io.*"%>
<%@page import="java.net.URL"%>
<%@ page contentType="text/html; charset=utf-8"%>
<!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>ServletContext를 이용한 자원 읽기2</title>
</head>
<body>
 
 <h3>ServletContext를 이용한 자원 읽기2</h3>
 <hr>
 <!-- ServletContext타입의 jsp내장객체명은 application
ServletContext 객체를 사용해서 웹 컨텍스트 아래 파일 자원 내용 읽어오기 -->

<!-- 변수 선언  -->
<% String resourcePath="/소스참조.txt" ; %>
 <font color="blue">
 소스참조.txt의 실제경로 :<%=application.getRealPath(resourcePath)%><br>
 소스참조.txt의 내용 : <br>
 </font>

 <%
  BufferedReader br = null;
  InputStreamReader isr = null;
  try {
   isr = new InputStreamReader(application.getResourceAsStream(resourcePath));
   br = new BufferedReader(isr);
   String st = null;
   while ((st = br.readLine()) != null) {
    out.println(st + "<br>");
   }

  } catch (Exception e) {
   e.printStackTrace();
  } finally {
   try {
    if (br != null) br.close();
    if (isr != null) isr.close();
   } catch (Exception e) {
    e.printStackTrace();
   }
  }
 %>
</body>
</html>

 

-----------------------------  요렇게로도 할 수 있어요!!!--------------------------

 

<%@page import="java.io.*"%>
<%@page import="java.net.URL"%>
<%@ page contentType="text/html; charset=utf-8"%>
<!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>ServletContext를 이용한 자원 읽기3</title>
</head>
<body>
 
 <h3>ServletContext를 이용한 자원 읽기3</h3>
 <hr>
 <!-- ServletContext타입의 jsp내장객체명은 application
ServletContext 객체를 사용해서 웹 컨텍스트 아래 파일 자원 내용 읽어오기 -->

<!-- 변수 선언  -->
<% String resourcePath="/소스참조.txt" ; %>
 <font color="blue">
 소스참조.txt의 실제경로 :<%=application.getRealPath(resourcePath)%><br>
 소스참조.txt의 내용 : <br>
 </font>

 <%
  BufferedReader br = null;
  InputStreamReader isr = null;
  try {
   URL url = application.getResource(resourcePath);
   isr = new InputStreamReader(url.openStream());
   br = new BufferedReader(isr);
   String st = null;
   while ((st = br.readLine()) != null) {
    out.println(st + "<br>");
   }

  } catch (Exception e) {
   e.printStackTrace();
  } finally {
   try {
    if (br != null) br.close();
    if (isr != null) isr.close();
   } catch (Exception e) {
    e.printStackTrace();
   }
  }
 %>
</body>
</html>

 

 

 

 usePageContext.jsp

 <%@ page contentType="text/html; charset=utf-8"%>
<!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> usePageContext.jsp</title>
</head>
<body>
 <%
  //pageContext.getRequest()의 리턴 타입은 ServletRequest인데, JSP페이지가 HTTP요청을 처리하므로 HttpServletRequest로 형변환 
  HttpServletRequest httpRequest = (HttpServletRequest) pageContext.getRequest();
 %>

 

 request 기본 객체와 pageContext.getRequest()의 동일 여부:

 

 <!-- //리턴 값이 같은 객체인지를 검사한다. -->
 <%=request == httpRequest%>

 

<br> pageContext.getOut() 메서드를 사용한 데이터 출력:

 

 <!-- pageContext.getOut().println()은 out.println()과 동일하다. -->
 <%  pageContext.getOut().println("안녕하세요!"); %>
</body>
</html>

 

<%@ page contentType="text/html; charset=utf-8"%>
<!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>outTest.jsp</title>
</head>
<body>


<%= 10%3 %><br> <!-- Expression -->
<% out.print(10%3); %><br> <!-- Scriptlet -->
${10%3}<br> <!-- EL(Expression Language) -->


</body>
</html>

http://www.boho.or.kr/kor/check/check_03.jsp

 

 

 

 

위 사이트에 접속하셔서

 

점검하기 -> 악성봇 감염 확인

 

메뉴를 클릭만 하시면 됩니다.

<%@ page import="com.shop.model.UserVo"%>

<%@ page contentType="text/html; charset=utf-8"%>


  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ko">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>Sing Up</title>

<link rel="stylesheet" href="https://user.design.co.kr/images/user/2006/basic/regi.css" type="text/css">

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script language="javascript" src="https://user.design.co.kr/jscript/registration.2013.js"></script>

<script language="javascript" src="https://user.design.co.kr/findaddress/findaddress.js"></script>


<script language="javascript">

</script>


</head>

<body>


<!--[if lt IE 9]>

<style>

.main_layout { width:752px}

.amv_text{ line-height: 37px; }

  </style>

<![endif]-->

<div class = "main_layout" >

<div class="main_title">

<h2>회원 가입 정보 확인</h2>

<br>

</div>

<%

UserVo user = (UserVo)session.getAttribute("user");

%>

 

 


<table cellpadding="0" cellspacing="0" border="0"  class="tbl">

<tr>

<th >아이디</th>

<td >

<input type="text" name="userid" id="userid" maxlength=25 value="<%=user.getUserid()%>">&nbsp;

</td>

</tr>

<tr>

<th >비밀번호</th>

<td ><input type="password" name="passwd" maxlength=12 value="${user.passwd}">

6~12자를 사용할 수 있습니다.</td>

</tr>

<tr>

<th >비밀번호 확인</td>

<td><input type="password" name="passwd_confirm" maxlength=12> 비밀번호를 한번 더 입력하세요</td>

</tr>

</table>


<table cellpadding="0" cellspacing="0" border="0"  class="tbl">

<tr>

<th >성명</th>

<td ><input type="text" name="username" id="username" maxlength=25 value="${user.username}" ></td>

</tr>

<tr>

<th >성별</th>

<td>

<% if(user.getGender() == 'M') { %>

<input type="radio" name="gender" value="M"  class="nw"  >

남&nbsp;&nbsp;&nbsp;&nbsp;

<% } else { %>

<input type="radio" name="gender" value="F"  class="nw" checked>

<% }%>

</td>

</tr>

<tr>

<th>생년월일</th>

<td ><input type="text" name="birth_year"

style="width:50px;font:12px;border:1px solid #DDD;" maxlength="4" value="<%= user.getBirth().getYear()+1900 %>" > 년 <input

type="text" name="birth_month"

style="width:30px;font:12px;border:1px solid #DDD;" maxlength="2" value="<%= user.getBirth().getMonth()+1 %>" > 월 <input

type="text" name ="birth_day"

style="width:30px;font:12px;border:1px solid #DDD;" maxlength="2" value="<%= user.getBirth().getDate() %>" > 일  (<input type=radio name=solar value=1 class="nw">양/<input type=radio name=solar

value=0  class="nw">음)

</td>

        </tr>


<tr>

        <th >이메일</th>

<td >

<input type="text" name="email1" style="width:120px;" value="${user.getEmail()}" >@

<input type="text" name="email2" value="" maxlength="20" readonly style="background:#efefef"> 

<select name="email_address1" onchange="chk_frm(this);" style="width:120px;font:12px;border:1px solid #DDD;" abled>

<option value="naver.com" selected>naver.com</option>

<option value="hanmail.net" >hanmail.net</option>

<option value="gmail.com" >gmail.com</option>

<option value="nate.com" >nate.com</option>

<option value="lycos.co.kr" >lycos.co.kr</option>

<option value="paran.com" >paran.com</option>

<option value="korea.com" >korea.com</option>

<option value="hotmail.com" >hotmail.com</option>

<option value="hanmir.com" >hanmir.com</option>

<option value="hananet.net" >hananet.net</option>

<option value="hanafos.com" >hanafos.com</option>

<option value="freechal.com" >freechal.com</option>

<option value="empal.com" >empal.com</option>

<option value="dreamwiz.com" >dreamwiz.com</option>

<option value="yahoo.co.kr"  >yahoo.co.kr</option>

<option value="write" >직접입력</option>

</select>

</td>

        </tr>


<tr>

        <th>주소</th>

<td>

<input name="u_zipcode1" type="text" readonly> - <input type="text" name="u_zipcode2" readonly>

<a href="javascript:FindAddress('regi_form', 'u_zipcode1', 'u_zipcode2', 'u_addr1', 'u_addr2');"><img src="https://user.design.co.kr/images/user/2006/basic/b_post.gif" style="vertical-align:-4px;"></a>

<input type="text" name=address1

style="width:300px;font:12px;border:1px solid #DDD;" readonly><br>

<input type="text" name=address2 style="width:300px;font:12px;border:1px solid #DDD;"><br>

* 정기구독신청, 이벤트 당첨 상품 등의 배송을 위해 정확한 주소를 기입해 주세요.

</td>

        </tr>


        

<tr>

        <th >전화번호</th>

<td >

<input type="text" name=phone1 style="width:50px;font:12px;border:1px solid #DDD;" value="<%=user.getPhone().substring(0,3) %>">

<input type="text" name="phone2" style="width:70px;font:12px;border:1px solid #DDD;" value="<%=user.getPhone().substring(3, 7) %>">

<input type="text" name="phone3" style="width:70px;font:12px;border:1px solid #DDD;" value="<%=user.getPhone().substring(7, 11) %>">

</td>

        </tr>


        <tr>

        <th>휴대전화</th>

<td><select

name="mobile1" style="width:60px;font:12px;" >

<option value="010" selected>010</option>

<option value="011" >011</option>

<option value="017" >017</option>

<option value="016" >016</option>

<option value="018" >018</option>

<option value="019" >019</option>

</select> - <input type="text" name="mobile2"

style="width:70px;font:12px;border:1px solid #DDD;" value="" > - <input

type="text" name="mobile3" style="width:70px;font:12px;border:1px solid #DDD;" value="" >

<p style="margin:3px 0 0 0;">비밀번호를 잊어버렸을 때, 확인받을 수 있는 휴대폰 번호를 넣으세요.</p>

</td>

        </tr>

        <tr>

        <th >블러그 or 홈페이지</th>

<td ><input

type="text" name=blog style="width:300px;font:12px;border:1px

solid #DDD;" value="http://">  </td>

        </tr>

<tr>

        <th>메일링 수신여부</th>

<td>

제공하는 매거진 컨텐츠 및 이벤트 내용이 담긴 서비스를 받아 보시겠습니까?<br>

<b>단, 정기구독 신청 확인 동의 기본정보는 수신 동의와 상관 없이 자동 발송 됩니다.</b><br>

뉴스레터 <input type="radio" name="letter" value="y"  class="nw"> 예&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="u_mail_yn" value="n"  class="nw"> 아니오

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

SMS <input type="radio" name="sms" value="y"  class="nw"> 예&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="u_sms_yn" value="n"  class="nw"> 아니오

</td>

        </tr>

<tr>

        <th>관심 매거진</th>

<td>

관심이 있는 것에 선택해주세요.

<table border="0" cellpadding="0" cellspacing="0" class="nonetbl">

<tr>

<td colspan="4"><input type="checkbox" name="all" onclick="check_all();"  class="nw"> 전체 선택</td>

</tr>

<tr>

<td width="250" colspan="2"><input type="checkbox" name="design" value="design" onclick="unlock();"  class="nw"> 자켓</td>

<td width="250" colspan="2"><input type="checkbox" name="happy" value="happy" onclick="unlock();"  class="nw"> 코트</td>

</tr>

<tr>

<td width="125"><input type="checkbox" name="mywedding" value="mywedding" onclick="unlock();"  class="nw"> 셔츠</td>

<td width="125"><input type="checkbox" name="momnenfant" value="momnenfant" onclick="unlock();"  class="nw"> 바지</td>

<td width="125"><input type="checkbox" name="luxury" value="luxury" onclick="unlock();"  class="nw"> 모자</td>

<!--td><input type="checkbox" name="dove" value="dove" onclick="unlock();"> 도베</td-->

<td width="125"><input type="checkbox" name="mens" value="mens" onclick="unlock();"  class="nw"> 기타 및 악세사리</td>                

</tr>

</table>

</td>

        </tr>

        </table>

<div style="text-align:center;margin:20px 0 0 0;">

<a href="javascript:Registration_OnSubmit();"><img src="https://user.design.co.kr/images/user/2006/basic/b_confir.gif"></a>&nbsp;&nbsp;&nbsp;<a

href="http://www.design.co.kr"><img src="https://user.design.co.kr/images/user/2006/basic/b_can.gif"></a>

        </div>

</form>

</div>



</body>

</html>

<!-- 

    <tr>

            <th>쇼핑레터 수신여부</th>

            <td width="515" style="padding:12px 0 12px 15px;"><input type="radio" name="u_mail_shop_yn" value=y> 예&nbsp;&nbsp;&nbsp;&nbsp;<input type="radio" name="u_mail_shop_yn" value=n> 아니오</td>

        </tr>

<tr>

<td background="https://user.design.co.kr/images/user/2006/basic/k_bg_dot.gif" height="1" colspan="2"></td>

</tr>


-->

'2020년도 이전 > temp' 카테고리의 다른 글

joinProcessServlet.java  (0) 2013.08.01
joinDAO.java  (0) 2013.08.01
서블릿 -- LoginServlet.java  (0) 2013.07.31
회원가입 디비 연결하자~~~ LoginDAO  (0) 2013.07.31
회원가입 자바로 만들기 - UserVo  (0) 2013.07.31

package com.shop.controller;


import java.io.IOException;

import java.io.PrintWriter;


import javax.servlet.RequestDispatcher;

import javax.servlet.ServletContext;

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;


import com.shop.model.LoginDAO;

import com.shop.model.UserVo;


@WebServlet("/login.do")

public class LoginServlet extends HttpServlet {

private static final long serialVersionUID = 1L;


    public LoginServlet() {

        super();

    }


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//요청 처리후 응답을 위한 마임타입과 문자셋 설정

response.setContentType("text/html;charset=utf-8");

//응답 결과를 클라이언트에게 보내기 위해서 문자스트림을 생성

PrintWriter out = response.getWriter();

//파라미터 받아오기

ServletContext sc = getServletContext();

RequestDispatcher rd = null;

String uid = request.getParameter("userid");

String pwd = request.getParameter("passwd");

HttpSession session = request.getSession();

LoginDAO dao = new LoginDAO(); 

UserVo user = dao.loginProc(uid, pwd);

if(user != null){

rd = sc.getRequestDispatcher("/join_confirm.jsp");

session.setAttribute("user", user);

rd.forward(request, response);

} else {

response.sendRedirect("./loginFail.jsp");

}

}

}

'2020년도 이전 > temp' 카테고리의 다른 글

joinDAO.java  (0) 2013.08.01
join_confirm --- 수정중!!  (0) 2013.07.31
회원가입 디비 연결하자~~~ LoginDAO  (0) 2013.07.31
회원가입 자바로 만들기 - UserVo  (0) 2013.07.31
회원가입 테이블 및 초기 정보 입력  (0) 2013.07.31

package com.shop.model;


import java.sql.*;

import javax.sql.*;

import javax.naming.*;


public class LoginDAO {

public Connection dbCon(){

//Tomcat Context로 부터 jdbc/oracle이름의 DataSource를 가져와서 

//DB Connection객체를 생성해서 리턴

//이 작업을 반복해서 하지 않도록 메서드로 작성.

Connection con = null;

try{

Context ctx = new InitialContext();

Context tomcat = (Context)ctx.lookup("java:comp/env");

DataSource ds = (DataSource)tomcat.lookup("jdbc/oracle");

con = ds.getConnection();

}catch(Exception e){

e.printStackTrace();

}

return con;

}//dbCon end

public void dbClose(Connection con, Statement stat, ResultSet rs){

try{

if(con!=null) con.close();

if(stat!=null) stat.close();

if(rs!=null) rs.close();

}catch(Exception e){

e.printStackTrace();

}

}//dbClose end

public UserVo loginProc(String uid, String pwd){

Connection con = null;

PreparedStatement stat = null;

ResultSet rs = null;

String sql = "select * from userinfo where userid = ? and passwd = ?";

UserVo vo = null;

try{

con = dbCon();

stat = con.prepareStatement(sql);

stat.setString(1, uid);

stat.setString(2, pwd);

rs = stat.executeQuery();

while(rs.next()){

vo = new UserVo();

vo.setAddress(rs.getString("address"));

vo.setUserid(uid);

vo.setPasswd(pwd);

vo.setBirth(rs.getDate("birth"));

vo.setBlog(rs.getString("blog"));

vo.setEmail(rs.getString("email"));

vo.setGender(rs.getString("gender").charAt(0));

vo.setSms(rs.getString("sms").charAt(0));

vo.setLetter(rs.getString("letter").charAt(0));

vo.setPhone(rs.getString("phone"));

vo.setMobile(rs.getString("mobile"));

vo.setUsername(rs.getString("username"));

}//while end

}catch(Exception e){

e.printStackTrace();

}finally{

dbClose(con,stat,rs);

}

return vo;

}//loginCheck() end

}



'2020년도 이전 > temp' 카테고리의 다른 글

joinDAO.java  (0) 2013.08.01
join_confirm --- 수정중!!  (0) 2013.07.31
서블릿 -- LoginServlet.java  (0) 2013.07.31
회원가입 자바로 만들기 - UserVo  (0) 2013.07.31
회원가입 테이블 및 초기 정보 입력  (0) 2013.07.31

+ Recent posts