<!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">
var xhr;
function createRequest(){
if(window.ActiveXObject)
xhr = new ActiveXObject("Microsoft.XMLHTTP");
else if(window.XMLHttpRequest)
xhr = new XMLHttpRequest();
}

function test(){
createRequest(); // 함수호출로 사용자의 브라우저를 판단한 후 XMLHttprequest객체를 얻어내었다.
xhr.onreadystatechange = res; // 서버에서 응답이 전달될 때 그 응답을 받을 함수
var str = document.all.sel.value;
var param = "sel="+escape(encodeURIComponent(str));// 한글처
xhr.open("get", "innerHTMLEx2.jsp?"+param, true); // 요청방식과 요청할 페이지 비동기식 설정
xhr.send(null); // 서버요청 수행
}

function res(){
if(xhr.readyState == 4) // 서버 데이터 처리가 완료된 경우 : 4
if(xhr.status == 200){// 정상적인 완료 : 200
var str = xhr.responseText; // 응답 문자열
var tt = document.getElementById("tt");
tt.innerHTML = str;
}
}
</script>
</head>
<body>
과정 : <select id="sel">
<option value="과정1">과정1
<option value="과정2">과정2
</select><input type="button" value="보내기" onclick="test()">
<div id="tt" style="border:1 solid lightsteelblue;width:300px;height:100px;background:#dedede">
&nbsp;
</div>
</body>
</html> <%@page import="java.net.URLDecoder"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%
String sel = URLDecoder.decode(
request.getParameter("sel"),"utf-8");
String code = "";
if(sel.equals("과정1"))
code = "JAVA, JSP, Ajax, Struts";
else if(sel.equals("과정2"))
code = "JAVA, XML, Flex, Struts";
else
code = "준비 중...";
%>
<%=code %>
by Anna 안나 2009. 1. 5. 13:31