넷빈(Netbeans)6.8에서 jax-rs 서버와 클라이언트 작성하기 02 - 클라이언트

0

Written on 오전 4:20 by 강여사(J.Y.Kang)

이제 클라이언트 프로젝트를 작성하도록 하겠습니다.

새로 프로젝트를 만듭니다.
파일 - 새 프로젝트
Java Web - Web application 선택

다음 클릭
프로젝트의 이름은 CustomerTestApp 라고 줬습니다.

경로는 적당히

다음 클릭 서버는 역시 글래스피시 v3 도메인

버전은 EE6 으로 줬습니다. (EE5 도 당연 가능합니다)

마침 클릭 이제 REST 클라이언트 스텁을 만들도록 하겠습니다.

프로젝트에서 오른쪽 마우스 클릭 - new - other Web Service - RESTful Web Service Client Stubs 선택
다음 클릭 REST 웹 서비스 프로젝트를 선택합니다.

Add project 버튼을 눌러 좀전에 작성한 서버 프로젝트(CustomerDB)를 선택합니다.

그리고 원래 창으로 돌아오면 그림과 같이 되어 있습니다.

마침 클릭 프로젝트의 web page 안에 rest 폴더 안에 보면 teststub.html 있습니다.

run file 로 이 파일을 실행합니다. 아래 그림과 같이 정상적으로 나와야 다음 작업이 가능합니다.

이제 여기서부터는 노가다..--; 대충 만들었습니다. 각자 알아서 할것

저는 자바스크립트 하나를 추가하고 해당 함수 호출을 index.jsp 수정을 통해 진행했습니다.

프로젝트에서 오른쪽 마우스 클릭 - new - other Web - javascript 선택

다음 클릭 파일 이름에 customerapp 라고 주고

마침 클릭 해당 자바 스크립트 내용으로 다음을 붙여 넣습니다.

==============================================


/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

//Change this url value if necessary
var baseUrl = 'http://localhost:8080/CustomerDB/resources/';
var customersObj;
var discountCodesObj;

function getCustomers() {
if(customersObj == null)
customersObj = new Customers(baseUrl+'customers/');
return customersObj;
}

function getDiscountCodes() {
if(discountCodesObj == null)
discountCodesObj = new DiscountCodes(baseUrl+'discountCodes/');
return discountCodesObj;
}

//function to show all customers
function showCustomers() {
var customersObj = getCustomers();
var customers = customersObj.getItems();
document.write("<table border=1>");
for(i=0;i<customers.length;i++) {
var customer = customers[i];
document.write("<tr>");
document.write("<td>"+customer.getName()+"</td>");
document.write("<td>"+customer.getCustomerId()+"</td>");
document.write("</tr>");
}
document.write("</table>");
}

==============================================
그림 참조

그런 다음 index.jsp 파일을 수정합니다.

=======================================================
<%--
Document : index
Created on : 2009. 12. 16, ?ㅽ썑 8:49:11
Author : Administrator
--%>

<%@page contentType="text/html" pageEncoding="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>JSP Page</title>
<!-- JS_DECLARE_START - DO NOT REMOVE-->
<script type="text/javascript" src="./rest/Support.js"></script>
<script type="text/javascript" src="./main.js"></script>
<script type="text/javascript" src="./rest/customerdb/CustomerDB.js"></script>
<script type="text/javascript" src="./rest/customerdb/Customers.js"></script>
<script type="text/javascript" src="./rest/customerdb/Customer.js"></script>
<script type="text/javascript" src="./rest/customerdb/DiscountCodes.js"></script>
<script type="text/javascript" src="./rest/customerdb/DiscountCode.js"></script>
<script type="text/javascript" src="./customerapp.js"></script>
<!-- JS_DECLARE_END - DO NOT REMOVE-->
</head>
<body>
<h1>Hello World!</h1>
<script type="text/javascript">
showCustomers();
</script>

</body>
</html>

======================================================
그림 참조

프로젝트를 실행하여 다음과 같이 뜨면 정상 출력입니다.


나머지 클라이언트 시리즈는 나중에..또는 각자 알아서.. --;

If you enjoyed this post Subscribe to our feed


No Comment

댓글 쓰기