Jeeve Management and Servlet ProgrammingJeeve´Â Internet Information Server·Î½á À¥¼¹ö¿Í°°Àº ±â´ÉÀ» ¼öÇàÇÏ´Â ¼¹öÀÌ´Ù. ´ÙÀ½ÀÇ »çÀÌÆ®¿¡¼ Jeeve¸¦ ´Ù¿î ·Îµå ¹ÞÀ» ¼ö ÀÖ´Ù. »ç¿ëȯ°æÀº Windows95/NT, SolarisÀ̸ç, µÎ OS¿¡ ±¸ºÐ¾øÀÌ ½ÇÇàÇÒ ¼ö ÀÖµµ·Ï µÇ¾îÀÖ´Ù.
¾ÐÃàÆÄÀÏÀ» Ç®¾îÁÖ´Â °Í¸¸À¸·Î ¼³Ä¡°¡ ³¡³´Ù.
ÃÖ±Ù¿¡ µîÀåÇÏ´Â »ó¿ë À¥¼¹ö´Â ȯ°æ ¼³Á¤¿¡ ÇÊ¿äÇÑ CGI ÇÁ·Î±×·¥°ú
¹®¼¸¦ Á¦°øÇÑ´Ù. Jeeveµµ ¸¶Âù°¡Áö·Î ȯ°æ¼³Á¤¿¡ ÇÊ¿äÇÑ ¾ÖÇø´°ú
¹®¼µéÀ» Á¦°øÇϴµ¥, ÀÌ·± ¾ÖÇø´ÀÌ Æ÷ÇÔµÈ ¹®¼´Â, ¼¹ö¸¦ ½ÇÇà ÇßÀ»¶§
½ÇÇàµÇ´Â ±âº» ȨÆäÀÌÁö¿¡ ÀÖ´Ù.[±×¸² 1]
![[±×¸² 2] Login to Administration](login.jpg)
[±×¸² 2] Login to Administration
Alias±â´ÉÀº local µð½ºÅ©¿¡ ÀÖ´Â ÆÄÀÏÀ̳ª ¼ºê¸´À» ¿ÜºÎ¿¡¼ URL·Î ã¾Æ°¥ ¼ö ÀÖµµ·ÏÇÑ´Ù. ´ÙÀ½Àº File AliasingÀ» µî·ÏÇÏ´Â aliases.propertiesÆÄÀϰú
aliases.properties
......
/=public_html
/cgi-bin=cgi-bin
/admin=admin/html
/doc=doc
/applet=servlets
/icons=icons
/~=public_html/usr
......
¼ºê¸´Àº °ü¸®ÀÚ¿¡ ÀÇÇØ¼ Jeeve¼¹ö°¡ ½ÇÇàµÉ¶§
ÀÚµ¿À¸·Î ·ÎµåÇÒ ¼ö ÀÖµµ·Ï ȯ°æ¼³Á¤À» ÇØÁÖ¾î¾ß ÇÑ´Ù.
local¿¡ ÀÖ´Â ¼ºí¸´°ú remote¿¡ ÀÖ´Â ¼ºí¸´À» ·ÎµåÇÒ ¼ö ÀÖ´Ù.
·Îµå ÇϰíÀÚ ÇÏ´Â ¼ºê¸´ÀÇ À̸§°ú ¾Æ±Ô¸ÕÆ®,
Ŭ·¡½º À̸§À» ÆÐŰÁö À̸§±îÁö Á¤È®ÇÏ°Ô Àû°í(È®ÀåÀÚ .class¸¦ »«´Ù) µî·ÏÇÑ´Ù.
±×·¯¸é, ´ÙÀ½°ú °°ÀÌ servlets.propertiesÀÌ °»½ÅµÈ´Ù.µî·ÏµÈ ¼ºí¸´À» È£ÃâÇϱâ À§Çؼ´Â ´ÙÀ½°ú °°Àº URLÇüÅ·Π¿ÀÇÂÇÑ´Ù.servlets.properties # Servlets Properties # #.codebase=URL where the code is located # .code=class name (foo or foo.class) # .initArgs=list of {name, value} pairs which can be accessed # by the servlet using the servlet API calls # # For example: # rcounter.codebase=http://www.javasoft.com/~pavani/classes/ # rcounter.code=rcounter.class # ...... # admin servlet admin.code=sun.server.http.AdminServlet ####################### Demo Servlets ############################ # local counter counter.code=Counter counter.initArgs=\ initial=0 # phone servlet phone.code=PhoneServlet phone.initArgs=\ phonelist=servlets/phonelist ......
rules.properties # Servlet rules properties # # This file specifies the translation rules for invoking servlets. # The syntax is: # #= # # where is the virtual path used to invoke the servlet, # and is the name of the servlet. Surrounding white space # is ignored. The ordering of the rules is not important, as the longest # match will always be used first. /=file /cgi-bin=cgi /imagemap=imagemap /servlet=invoker /counter.html=counter /phone.html=phone /snoop.html=snoop /finger.html=finger /fun.html=fun ......
|
|
|
| [±×¸² 4] Jeeves File Aliasing | [±×¸² 5] Jeeves Servlet Aliasing | [±×¸² 6] Servlet Loading |
mime.properties
# Default Mime Type
*=text/plain
# Mime Types
java=text/plain
html=text/html
htm=text/html
body=text/html
txt=text/plain
rtx=text/richtext
ps=application/x-postscript
class=application/java
......
Jeeves ¿ª½Ã ACL(Access Control Lists)¿¡ ÀÇÇØ¼ À¥ÆäÀÌÁö³ª
¼ºí¸´°ú °°Àº ¸®¼Ò½º¸¦ »ç¿ëÇÒ ¼ö ÀÖ´Â »ç¿ëÀÚ¸¦ µî·Ï/»èÁ¦ÇÒ ¼ö ÀÖ´Ù.
°¢ »ç¿ëÀÚ´Â ID¿Í Password¸¦ °¡Áú ¼ö ÀÖ°í, RealmÀ» ÀÌ¿ëÇØ¼
°°Àº ID·Î ¼·Î´Ù¸¥ Á¢±Ù ¿µ¿ªÀ» ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.
(Jeeves A1.2¿¡¼´Â »õ·Î¿î realmÀ» ÁöÁ¤ÇÒ ¼ö ÀÖ´Â ±â´ÉÀº ¾ø°í
adminRealm, defaultRealm¸¸ Áö¿øÇÑ´Ù.)
Ưº°È÷ »ç¿ëÀÚÀÇ ±ÇÇÑÁß¿¡¼µµ ¾ÕºÎºÐÀÇ 'admin'°ú °°Àº °ü¸®ÀÚ ±ÇÇÑÀ»
ºÎ¿©ÇÒ ¼ö °¡ Àִµ¥, ¸¸¾à ½Ç¼ö¸¦ ÇØ¼ ¾ÏÈ£¸¦ Àؾî¹ö¸®¸é ´Ù½Ã´Â
´õÀÌ»ó ¼¹ö °ü¸®¸¦ ÇÒ ¼ö ¾øÀ¸¹Ç·Î Á¶½ÉÈ÷ µî·ÏÇØ¾ß Çϰí
½Ç¼ö°¡ ¾øµµ·Ï À¯ÀÇÇØ¾ß ÇÑ´Ù.
¿©±â °ü¸®ÀÚ È¸é¿¡¼ °»½ÅµÈ ³»¿ëÀº 'admin/realms'µð·ºÅ丮¿¡
°èÁ¤ÀÌ ÀÚµ¿À¸·Î µî·ÏµÈ´Ù. À̰÷¿¡´Â ¾ÏÈ£È µÇ¾î ÀÖ´Â ÆÄÀϵµ ÀÖÀ¸¹Ç·Î
°¡±ÞÀû ¼öÁ¤ÇÏÁö ¾Ê´Â °ÍÀÌ ÁÁ´Ù.
|
|
|
|
|
|
|
|
|
¿©±â¿¡¼´Â jeeveÀÇ http ¼¹ö±â´ÉÀÌ ¾î¶»°Ô ±¸ÇöµÇ°í, servlet ÀÇ ½ÇÇà ±¸Á¶¿¡ ´ëÇØ¼ ¾Ë¾Æº»´Ù. ƯÈ÷, ÀÚ¹ÙÀÇ µ¶Æ¯ÇÑ Æ¯Â¡Áß¿¡¼ ÀÚ¹Ù ÇÁ·Î±×·¥Àº °ð ¶óÀ̺귯¸®·Î½á ÇÁ·Î±×·¡¹Ö¿¡ »ç¿ëÇÒ ¼ö ÀÖ´Ù´Â Á¡ÀÌ´Ù. Áï JeeveÀÇ http internet server¿Í À¯»çÇÑ ÇÁ·Î±×·¥°ú Servlet°ú °°Àº ÇÁ·Î±×·¡¹ÖÀ» ÇÒ ¼ö ÀÖÀ¸¹Ç·Î, Jeeve¿Í ServletÀÇ API¿¡ ´ëÇØ¼ °£´ÜÈ÷ ¼³¸íÇÑ´Ù.
ÀϹÝÀûÀÎ Http Server(Daemon)Àº ½ÇÇà½ÃŰ¸é ¿©·¯°³ÀÇ ÇÁ·Î¼¼½º°¡ »ý¼ºµÇ¾î Client°¡ Á¢¼ÓÇϱ⸦ ±â´Ù¸°´Ù. Jeeveµµ ¸¶Âù°¡Áö·Î ¿©·¯°÷¿¡¼ °°Àº port·Î Á¢¼ÓÀ» ó¸®ÇÒ ¼ö ÀÖµµ·Ï Áö¿øÇϴµ¥ ´Ù¸¥Á¡Àº Thread·Î 󸮵ȴٴ °ÍÀÌ´Ù. ÀÚ¼¼È÷ ¸»Çϸé, ¼¹ö´Â Áö¼ÓÀûÀ¸·Î ClientÀÇ Á¢¼ÓÀ» ±â´Ù¸®°í ÀÖ°í Á¢¼ÓÀÌ ½ÃµµµÇ¸é ½º·¹µå¸¦ »ý¼ºÇؼ ¼ºñ½º¸¦ Çϰí, ´Ù½Ã Á¢¼ÓÀ» ±â´Ù¸®´Â ÇüÅÂÀÌ´Ù.
JeeveÀÇ ±âº» ±â´É ±¸Çö¿¡ »ç¿ëµÈ ÆÐŰÁö´Â ´ÙÀ½°ú °°´Ù.
À§¿¡¼ ¼³¸íÇÑ ¹Ù¿Í°°ÀÌ °ü¸®ÀÚ¿¡ÀÇÇØ µî·ÏµÈ ¼ºí¸´Àº ¼¹ö°¡
½ÇÇà µÉ¶§ ÀÚµ¿À¸·Î ·ÎµåµÈ´Ù. ±×¹Û¿¡ ¼ºí¸´Àº ÇÊ¿ä½Ã¿¡ ·Îµå µÈ´Ù.
µû¶ó¼, ¼ºí¸´Àº ÀÎÅͳݿ¡¼ ÀÚµ¿À¸·Î ·ÎµåµÇ¾î ½ÇÇà µÇ´Â
¾ÖÇø´°úµµ °°Àº ¹ÙÀÌÆ®ÄÚµå ÇüÅÂÀÇ °´Ã¼ÀÌ´Ù.
ÀϹÝÀûÀÎ À¥¼¹ö¸¦ ¼³Ä¡Çϸé imagemap°ú °°Àº ±âº»ÀûÀÎ CGI·çƾÀÌ Á¸ÀçÇϵíÀÌ, ¼ºí¸´ Áß¿¡´Â ±âº»ÀûÀÎ Core ServeltÀÌ ÀÖ°í, ´ÙÀ½°ú °°Àº ÆÐŰÁö µéÀÌ ÀÖ´Ù. ÆÐŰÁö Áß¿¡´Â À§¿¡¼ °£°£È÷ ¼³¸íÇÑ ÆÐŰÁöµéµµ Æ÷ÇԵǾî ÀÖ´Ù.
source code
import java.io.*;
import java.servlet.*;
import sun.server.html.*;
public class SimpleServlet extends Servlet {
public void service(ServletRequest req, ServletResponse res)
throws Exception
{
res.setContentType("text/html");
res.writeHeaders();
OutputStream out = res.getOutputStream();
String title = "SimpleServlet Output";
HtmlPage page = new HtmlPage(title);
page.addTagPair("H1", title);
page.addText("<P>This is output from SimpleServlet.");
page.write(out);
out.flush();
}
public String getServletInfo() {
return "A simple servlet";
}
}
HTML tag
<a href="/servlet/simpleservlet">Try it</a>
source code
import java.io.*;
import java.util.*;
import java.servlet.*;
public class SnoopServlet extends Servlet {
public void service(ServletRequest req, ServletResponse res)
throws IOException
{
res.setContentType("text/html");
res.setHeader("Pragma", "no-cache");
res.writeHeaders();
PrintStream out = new PrintStream(res.getOutputStream());
out.println("<html>");
out.println("<head><title>Snoop Servlet</title></head>");
out.println("<body>");
out.println("<h1>Request information:</h1>");
out.println("<pre>");
print(out, "Request method", req.getMethod());
print(out, "Request URI", req.getRequestURI());
print(out, "Request protocol", req.getProtocol());
print(out, "Servlet path", req.getServletPath());
print(out, "Path info", req.getPathInfo());
print(out, "Path translated", req.getPathTranslated());
print(out, "Query string", req.getQueryString());
print(out, "Content length", req.getContentLength());
print(out, "Content type", req.getContentType());
print(out, "Server name", req.getServerName());
print(out, "Server port", req.getServerPort());
print(out, "Remote user", req.getRemoteUser());
print(out, "Remote address", req.getRemoteAddr());
print(out, "Remote host", req.getRemoteHost());
print(out, "Authorization scheme", req.getAuthType());
out.println("</pre>");
/*
Hashtable params = req.getQueryParameters();
if (params.size() > 0) {
out.println("<h1>Servlet parameters:</h1>");
out.println("<pre>");
Enumeration e = params.keys();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
out.println(" " + name + " = " + (String)params.get(name));
}
out.println("</pre>");
}
*/
if (!req.getProtocol().equals("HTTP/0.9")) {
out.println("<h1>Request headers:</h1>");
out.println("<pre>");
String name;
for (int i = 0; (name = req.getHeaderName(i)) != null; i++) {
out.println(" " + name + ": " + req.getHeader(name));
}
out.println("</pre>");
}
out.println("</body></html>");
}
private void print(PrintStream out, String name, String value) {
out.print(" " + name + ": ");
out.println(value == null ? "<none>" : value);
}
private void print(PrintStream out, String name, int value) {
out.print(" " + name + ": ");
if (value == -1) {
out.println("<none>");
} else {
out.println(value);
}
}
private static final String UNKNOWN = "<unknown>";
public String getServletInfo() {
return "A servlet that shows the request headers sent by the client";
}
}
HTML tag
<a href="/snoop.html">Try it</a>
source code
import java.io.*;
import java.servlet.*;
import sun.server.html.*;
public class FunServlet extends Servlet {
public void service(ServletRequest req, ServletResponse res)
throws Exception
{
String line;
res.setContentType("text/html");
res.writeHeaders();
OutputStream out = res.getOutputStream();
DataInputStream in = new DataInputStream(req.getInputStream());
String title = "Servlet Demo";
HtmlPage page = new HtmlPage(title);
//
// Spew out html code that will make the browser load an applet.
// Setup the codebase right. Will work only in Java enabled browsers
//
page.addText("<applet code=NervousApplet.class codebase=\"../applet/\" height=200 width=1800>");
page.addText("<param name=text value=\"Jeeves can load Servlets!\">");
page.addText("</applet>");
page.write(out);
}
}
HTML tag
<a href="/fun.html">Try it</a>
source code
import java.io.*;
import java.servlet.*;
import sun.server.html.*;
public class FunServlet extends Servlet {
public void service(ServletRequest req, ServletResponse res)
throws Exception
{
String line;
res.setContentType("text/html");
res.writeHeaders();
OutputStream out = res.getOutputStream();
DataInputStream in = new DataInputStream(req.getInputStream());
String title = "Servlet Demo";
HtmlPage page = new HtmlPage(title);
//
// Spew out html code that will make the browser load an applet.
// Setup the codebase right. Will work only in Java enabled browsers
//
page.addText("<applet code=NervousApplet.class codebase=\"../applet/\" height=200 width=1800>");
page.addText("<param name=text value=\"Jeeves can load Servlets!\">");
page.addText("</applet>");
page.write(out);
}
}
HTML tag
<form action="/finger.html" method="GET">
<table>
<tr><td>Username:</td><td><input type="TEXT" name="user" size=10></td></tr>
<tr><td>Hostname:</td><td><input type="TEXT" name="hosts" size=10></td>
<td>leave blank for local host<br>
multiple hostnames may be separted by commas</td></tr>
<tr><td>Verbose:</td><td><input type="checkbox" name="verbose" value="yes" CHECKED></td></tr>
</table>
<input type="SUBMIT" value="Try it">,
</form>
|
|
| |
Áö±Ý±îÁö À¥ ¼¹ö·Î½á Jeeve¿Í ±âÁ¸ÀÇ CGI¿Í ºñ½ÁÇÑ ÇüÅÂÀÇ Java ÀÀ¿ë ÇÁ·Î±×·¥ÀÎ Servlet¿¡ ´ëÇØ¼ ¾Ë¾Æº¸¾Ò´Ù. CGI ÇÁ·Î±×·¥À» ½ÇÇàÇÏ¸é »õ·Ó°Ô ÇÁ·Î±×·¥ÀÌ LoadµÇ¾î ½ÇÇàµÇ°í ¿©·¯¸íÀÇ »ç¿ëÀÚ°¡ °°Àº CGI¸¦ ½ÇÇàÇÏ´õ¶óµµ °¢°¢ÀÇ CGIÇÁ·Î±×·¥ÀÌ »õ·Ó°Ô ·ÎµåµÇ¾î ½ÇÇàµÇ´Â ¹Ý¸é ServletÀº ¿©·¯°¡Áö ÀåÁ¡À» °¡Áö°í ÀÖ´Ù.
ServletÀº óÀ½ ½ÇÇàµÇ¸é Server°¡ downµÉ¶§ ±îÁö °è¼Ó ½ÇÇàµÇ¾î, ¿©·¯¸íÀÇ ´Ù¸¥ »ç¿ëÀÚ°¡ ServletÀ» Á¢¼ÓÇϸé Thread¸¦ »ý¼ºÇÏ¿© ¼ºñ½ºÇÑ´Ù. ¸¶Ä¡ Daemon°ú °°Àº ±â´ÉÀ» À¯ÁöÇÑ´Ù. ¶ÇÇÑ, ServletÀº Áö¼ÓÀûÀ¸·Î ½ÇÇàµÇ°í ÀÖÀ¸¹Ç·Î HTTPDÀÇ ±Ùº»ÀûÀÎ ¹®Á¦ÀÎ ConnectionÀ» À¯ÁöÇÒ ¼ö ÀÖ´Ù´Â ÀåÁ¡À» °¡Áö°í ÀÖ´Ù. ÇÑÆí, Jeeve¿Í ServletÀº ¸ðµÎ ÀÚ¹Ù·Î °³¹ßµÇ¾ú±â ¶§¹®ÀÇ ±âŸ ÀÚ¹ÙÀÇ ÀåÁ¡ÀÎ Ç÷§Æû µ¶¸³ÀûÀ̰í(»õ·Ó°Ô ÄÄÆÄÀÏÇÒ Çʿ䰡 ¾ø´Ù.), µ¿ÀûÀ̸ç È®À强/À̽ļº/À¯Áöº¸¼ö ±â´ÉÀÌ ¶Ù¾î³ª¸ç, ÇÁ·Î±×·¥ »çÀÌÁî°¡ ¾ÆÁÖ À۱⠶§¹®¿¡ ½Ã½ºÅÛ ºÎÇϰ¡ ÀÛ´Ù. ¾ÆÁ÷±îÁö Á¤½Ä ¹öÀüÀÇ Jeeve°¡ ³ª¿ÀÁö ¾Ê¾ÒÁö¸¸, ÀÚ¹Ù·Î °³¹ßµÈ HotJava À¥ ºê¶ó¿ìÀú¿Í ÇÔ²² ¾ÕÀ¸·Î Å©°Ô ±â´ëµÈ´Ù.
±×¹ÛÀÇ »õ·Î¿î ¼Ò½ÄÀ̳ª ±Ã±ÝÇÑ »çÇ×Àº ¸ÞÀϸµ ¸®½ºÆ®¸¦ ÅëÇØ¼ ¾òÀ» ¼ö ÀÖ´Ù.