ํฐ์คํ ๋ฆฌ ๋ทฐ
โ ์ ๋ชฉ์ ์
๋ ฅ ํ์ ์ค๋ฅธ์ชฝ ํ์ดํ ํค๋ฅผ ๋๋ฌ ์ฃผ์ญ์์ค.
gethint.jsp ์์ค
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%
response.setHeader("Expires", "-1");
String[] a = new String[30];
//Fill up array with names
a[1-1]="Anna" ;
a[2-1]="Brittany" ;
a[3-1]="Cinderella" ;
a[4-1]="Diana" ;
a[5-1]="Eva" ;
a[6-1]="Fiona" ;
a[7-1]="Gunda" ;
a[8-1]="Hege" ;
a[9-1]="Inga" ;
a[10-1]="Johanna" ;
a[11-1]="Kitty" ;
a[12-1]="Linda" ;
a[13-1]="Nina" ;
a[14-1]="Ophelia" ;
a[15-1]="Petunia" ;
a[16-1]="Amanda" ;
a[17-1]="Raquel" ;
a[18-1]="Cindy" ;
a[19-1]="Doris" ;
a[20-1]="Eve" ;
a[21-1]="Evita" ;
a[22-1]="Sunniva" ;
a[23-1]="Tove" ;
a[24-1]="Unni" ;
a[25-1]="Violet" ;
a[26-1]="Liza" ;
a[27-1]="Elizabeth" ;
a[28-1]="Ellen" ;
a[29-1]="Wenche" ;
a[30-1]="Vicky" ;
//get the q parameter from URL
String q = request.getParameter("q");
if(q != null)
q = q.toUpperCase();
//lookup all hints from array if length of q>0
//์กฐํ ๊ฒฐ๊ณผ๋ฅผ ์ ์ฅํ ๋ณ์
String hint = "";
if (q.length() > 0){
for (int i = 0; i < 30; i++){
//๊ฒ์์ด์ ๊ธธ์ด
int qLength = q.length();
//๊ฐ ๋ฐฐ์ด์์์ ๊ธธ์ด
int aLength = a[i].length();
//๊ฒ์์ด์ ๋น๊ตํ ๋ฐฐ์ด์์์ ์ผ๋ถ๋ถ
String substr = a[i].substring(0,
(qLength > aLength ? aLength : qLength)
);
if ( q.equalsIgnoreCase(substr) ){
if (hint.equals(""))
hint=a[i];
else
hint=hint + " , " + a[i];
}
}< BR > }
//Output "no suggestion" if no hint were found
//or output the correct values
if (hint.equals(""))
out.write("no suggestion");
else
out.write(hint);
< P > %>
suggest.jsp ์์ค
<%@ 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>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
<script type="text/javascript"
src="js/ajax_basic.js"></script>
<script type="text/javascript">
var xmlhttp;
function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
var url="gethint.jsp";
//sidํ๋ผ๋ฏธํฐ๋ ๊ฐ์ ์ ๋ฌํ๋ ๋ชฉ์ ๋ณด๋ค๋ ํญ์ ๋ค๋ฅธ URL์ฃผ์๋ฅผ
//ํธ์ถํ๊ธฐ ์ํ ์ฅ์น์ด๋ค.
var data = "q="+str+"&sid="+Math.random();
var method = 'GET';
sendRequest(
method, //Http ์ ์ก๋ฐฉ์
url, //์๋ฒ ์ฃผ์
data, //์๋ฒ์ ์ ๋ฌํ ํ๋ผ๋ฏธํฐ
stateChanged //์๋ต์ ๋ฐ์ํ ํธ๋ค๋ฌ ํจ์ ๋ ํผ๋ฐ์ค
);
}
function stateChanged()
{
if (request.readyState==4)
{
document.getElementById("txtHint").innerHTML=
request.responseText;
}
}
</script>
</head>
<body>
<form>First Name: <input type="text" id="txt1"
onkeyup="showHint(this.value)" /></form>
<p>Suggestions: <span id="txtHint"></span></p>
</body>
</html>
ajax_basic.js ์์ค
var request;
function getRequest(){
if(window.ActiveXObject){
try{
return new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
return new ActiveXObject(
"Microsoft.XMLHTTP");
}catch(e){
return null;
}
}
}else if(window.XMLHttpRequest){
return new XMLHttpRequest();
}else {
return null;
}
}
function sendRequest(
method, //Http ์ ์ก๋ฐฉ์
address, //์๋ฒ ์ฃผ์
data, //์๋ฒ์ ์ ๋ฌํ ํ๋ผ๋ฏธํฐ
handler //์๋ต์ ๋ฐ์ํ ํธ๋ค๋ฌ ํจ์ ๋ ํผ๋ฐ์ค
){
//xhr ๊ฐ์ฒด ์์ฑ
request = getRequest();
//์๋ต ํธ๋ค๋ฌ ๋ฑ๋ก
request.onreadystatechange = handler;
//์ ์ก๋ฐฉ์์ ๋ฐ๋ผ data ๋ฐ address๋ฅผ ์กฐ์ํ์
if(method == 'GET'){
address = address + "?" + data;
data = null;
}
//open
request.open(method,address,true);
//์์ฒญ์ header ์ค์
request.setRequestHeader(
"Content-Type",
"application/x-www-form-urlencoded");
//send
request.send(data);
}
'PROGRAMMING' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๋จ์ด๊ธฐ์ค ๊ฐํ CSS - word-break:keep-all (0) | 2011.01.27 |
---|---|
์ด๋ฒ์ฃผ๋ง์ ๊ณต๋ถํ ๋ด์ฉ. (0) | 2010.10.22 |
jstl ์ด์ฉ sql์กฐ์ (0) | 2010.07.08 |
jsp EL (0) | 2010.07.06 |
์ผ๋จ, ์๋๋ก์ด๋ ๊ฐ๋ฐ์ ๋ฑ๋ก (0) | 2010.07.06 |
- Total
- Today
- Yesterday
- JSTL
- php
- I Don't Care
- ์๋ธ๋ฆฟ
- ์๋ฐ์คํฌ๋ฆฝํธ
- ์นด๋ฐ์จ๋ผ์ธ
- ์น์์ด์ ์
- ๊ธฐํ
- 2ne1
- ๊ฒฝ์ ์ฉ์ด
- ํจ์
- ๋ด๋๋ด์ฐ
- EL
- ๋ฉ๋ฐฐํ
- 8๋ง์ผ
- JS
- jQuery
- ๋ณต๊ทผ์ด๋
- Ajax
- MySQL
- Servlet
- ์๋ฆฌ
- JavaScript
- JSON
- ์ธํจ์ด
- ์์์ฌ์ด๋
- JSP
- asp
- Java
- ๋์ค
์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
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 | 29 | 30 |