일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- 매일영어단어외우기
- 폭선우의무덤
- 아이유
- 피렌체
- 페이트그랜드오더
- 매일영어단어
- 어린궁기
- 나스닥
- 주작의용천제일검
- 미국주식
- 바람의나라
- 레어닉
- 영어단어
- 에미넴
- 일본패치
- 타라옷
- 바람의나라연
- 2차신수
- 북천황의감옥
- 매드클라운
- 수지
- 2차승급
- 페그오
- 체마1등
- 막피범
- 걸스데이
- 돌림판이벤트
- 보물수호
- Eminem
- 모바일바람의나라
- Today
- Total
티스의 이야기
무료 Ajax 강의 배우기 본문
무료 Ajax 강의 배우기
<%@ 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>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
<script type="text/javascript">
$(function () {
$("input").eq(3).click(function () {
var id= $("input:first").val();
var name = $("input").eq(1).val();
var xmlhttp;
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp = new ActiveXObeject("Microsoft.XMLHTTP");
}
xmlhttp.open("Get", "test.check?id="+id+"&name="+name,true);
xmlhttp.send();
xmlhttp.onreadystatechange = function () {
if(xmlhttp.readyState==4 && xmlhttp.status==200){
var data = xmlhttp.responseText;
$("input").eq(2).val(data);
}
}
});
});
</script>
</head>
<body>
<h2> PW 찾기 </h2>
<form action="#">
ID <input type="text" name="id"><br>
NAME <input type="text" name="name"><br>
당신의 Password <input type="text" name="pw"><br>
<input type="button" value="pw찾기">
<input type="submit" value="login">
</form>
</body>
</html>
jsp 파일을 하나 만들어 준다
코드는 바로 위의 것
코드는 이런식
바디는 이런식
web.xml을 만들어준다
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<display-name>Ajax_1103</display-name>
<servlet>
<servlet-name>go</servlet-name>
<servlet-class>Join.JoinCheck</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>go</servlet-name>
<url-pattern>*.check</url-pattern>
</servlet-mapping>
</web-app>
이게 코드
복사 해도 무방하다
서블렛은 제대로 만들어준다
Join.JoinCheck
Join 패키지 안에
JoinCheck 라는 서블렛이 필요하다
소,대문자 주의
doPost 메서드 안에
이것을 집어 넣는다
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String id = request.getParameter("id");
String name= request.getParameter("name");
String user="team01";
String password="team01";
String url="jdbc:oracle:thin:@192.168.30.14:1521:xe";
String driver="oracle.jdbc.driver.OracleDriver";
String result="";
try {
Class.forName(driver);
Connection con = DriverManager.getConnection(url, user, password);
String sql ="select pw from member where id=? and name=?";
PreparedStatement st = con.prepareStatement(sql);
st.setString(1, id);
st.setString(2, name);
ResultSet rs = st.executeQuery();
if(rs.next()){
result=rs.getString("pw");
}else{
result="pw 없네요";
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setAttribute("result", result);
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
out.println(result);
}
이렇게 뜨고 pw 찾기를 눌렀을때
DB에서 불러온다면 성공!
이때 주의사항은
doPost에서 굵은 글씨는 자신의 DB와 맞게 세팅해야 한다는 점 유의바란다
'프로그래밍' 카테고리의 다른 글
PHP-로그인 폼작성 (0) | 2016.06.13 |
---|---|
PHP-데이터베이스에서 선택 메뉴생성 (0) | 2016.06.10 |
cmd 기본 (0) | 2015.08.12 |
HTML 배우기 첫수업 (0) | 2015.08.12 |
HTML hypertextmarkuplanguage (0) | 2015.08.12 |