[Delphi] 웹프로그래밍 #3 - 코딩 심화
웹프로그래밍 03
지난번 강좌는 실행까지 부분이고 실제 코딩을 해보겠습니다.
Projects 창에서 WebModuleUnit1.pas 를 더블클릭하면
아래창이 나오고 마우스 오른쪽 버튼을 클릭하면 아래 팝업이 나옵니다.
Action Editor 창이 열리면
여기에서 Path를 추가할수 있습니다. Path 란
http://localhost/TEST/test.dll/list?page=1
list 같이 Path 를 추가하여 여러개의 하위서비스를 추가할수 있습니다.
기본은 "/" 라서 아무것도 없으면 기본이 처리됩니다.
Object Inspector 창에서
Events 탭에서 OnAction 이벤트를 추가하여 아래처러 코딩하면
procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
Response.Content :=
'<html>' +
'<head><title>Web Server Application</title></head>' +
'<body>List Page</body>' +
'</html>
end;
http://localhost/TEST/test.dll/list 로 접속하면
다음과 같은 결과를 얻을수 있습니다.
OnAction 에는 Request, Response 라는 객체가 선언되어 있는데요.
Request 값을 받아올때
Response 는 HTML 을 html을 출력할때 사용합니다.
GET 방식으로 page 값 받기
procedure TWebModule1.WebModule1WebActionItem1Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
page : String;
begin
// GET 방식의 값 읽어 오기
page := Request.QueryFields.Values['page'];
Response.Content :=
'<html>' +
'<head><title>Web Server Application</title></head>' +
'<body>List Page : ' + page + '</body>' +
'</html>+
end;
http://localhost/TEST/test.dll/list?page=5 – page 값에 5를 넣음
실행 결과
/info Action 추가하고
procedure TWebModule1.WebModule1WebActionItem2Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
begin
Response.Content := '<h3>Status</h3>'#13 +
'Method: ' + Request.Method + '<br>'#13 +
'ProtocolVersion: ' + Request.ProtocolVersion + '<br>'#13 +
'URL: ' + Request.URL + '<br>'#13 +
'Query: ' + Request.Query + '<br>'#13;+
end;
댓글
댓글 쓰기