±Û¾´ÀÌ :±è´öÅ 1998³â 4¿ù 23ÀÏ 01:31:43
¼ºí¸´¿¡¼ ÇÑ±Û Ã³¸®¸¦ ¹æ¹ýÀÌ ¿©·¯°¡Áö°¡ ÀÖÀ¸³ª, ´ÙÀ½ ¿¹Á¦ ÇÁ·Î±×·¥Àº
ÀÚ¹ÙÀÇ ÀϹÝÀûÀÎ À¯´ÏÄÚµå ó¸® ¸ðµ¨À» µû¸£¸é¼ ÇÁ·Î±×·¡¹ÖÀ» ÇÏ´Â
Ç¥ÁØÈµÈ ¹æ¹ýÀ̸ç, ÀÕÁ¡À¸·Î´Â ÇÁ·Î±×·¡¹ÖÇϱ⠰£ÆíÇÏ¸é¼ ÇÁ·Î±×·¥ÀÇ
º°´Ù¸¥ ¼öÁ¤¾øÀÌ ÇÊ¿ä¿¡ µû¶ó ¹®¼ ÀÎÄÚµùÀ» ¼Õ½±°Ô ¹Ù²Ü ¼ö ÀÖ´Â ¹æ¹ýÀÔ´Ï´Ù.
´Ü, ´ÙÀ½ ¼ºí¸´µé ¿¹Á¦ ÇÁ·Î±×·¥Àº JSDK (Java Servlet Developer Kit) 1.1
ȣȯ ȯ°æ¿¡ ¸ÂÃß¾îÁ® ÀÖ½À´Ï´Ù.
ÀÚ¹Ù°¡ Á»´õ ÀÎÄÚµù À̸§À» Á¦´ë·Î Áö¿øÇÏ°Ô µÇ¸é, ¿¹Á¦ ÇÁ·Î±×·¥³»ÀÇ
¾à°£ÀÇ ÁöÀúºÐÇÑ Äڵ嵵 ÇÊ¿ä¾ø¾îÁú °ÍÀÔ´Ï´Ù.
JSDK 1.1Àº JDK 1.2¿¡ ³»ÀåµÇ¾î ÀÖÀ¸¸ç javax.servlet ÆÐÅ°Áö 1.1°ú
servletrunner ÇÁ·Î±×·¥À¸·Î ÀÌ·ç¾îÁ® ÀÖ½À´Ï´Ù.
http://calab.kaist.ac.kr/~dtkim/java/ ¿¡¼ °¡Á®°¡½Ç ¼öµµ ÀÖ½À´Ï´Ù.
============ DoGetTest.java ============ import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class DoGetTest extends HttpServlet { public void doGet( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException { res.setContentType("text/html; charset=euc-kr"); // PrintWriter out = res.getWriter(); // servlet ÆÐÅ°Áö 1.1ÀÇ ¹ö±×! PrintWriter out = new PrintWriter( new OutputStreamWriter(res.getOutputStream(), "KSC5601") ); String title = "doGet Å×½ºÆ®"; out.println( "<HTML><HEAD><TITLE>" ); out.println( title ); out.println( "</TITLE></HEAD><BODY>" ); out.println( "<H1>" + title + "</H1>" ); out.println( "<P>HTML ¹®¼ÀÔ´Ï´Ù." ); out.println( "</BODY></HTML>" ); out.close(); } } ============ UTF8Servlet.java ============ import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class UTF8Servlet extends HttpServlet { public void doGet( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException { res.setContentType( "text/html; charset=utf-8" ); // PrintWriter out = res.getWriter(); // servlet ÆÐÅ°Áö 1.1 ¹ö±×! PrintWriter out = new PrintWriter( new OutputStreamWriter(res.getOutputStream(), "UTF8") ); String title = "UTF-8 Ãâ·Â Å×½ºÆ®"; out.println( "<HTML><HEAD><TITLE>" ); out.println( title ); out.println( "</TITLE></HEAD><BODY>" ); out.println( "<H1>" + title + "</H1>" ); out.println( "UTF-8 ÀÎÄÚµùÀÇ 8859-1¹®ÀÚ: " + "\u00a1\u00a2\u00a3\u00a4" ); out.println( "UTF-8 ÀÎÄÚµùÀÇ Çö´ë ÇÑ±Û ¹®ÀÚ: " + "\uac00\uac01\uac02\uac03" ); out.println( "</BODY></HTML>" ); out.close(); } } ============ UnicodeServlet.java ============ import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class UnicodeServlet extends HttpServlet { public void doGet( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException { res.setContentType( "text/html; charset=csUnicode" ); // PrintWriter out = res.getWriter(); // servlet ÆÐÅ°Áö 1.1 ¹ö±×! PrintWriter out = new PrintWriter( new OutputStreamWriter(res.getOutputStream(), "UnicodeLittle") ); String title = "À¯´ÏÄÚµå Ãâ·Â Å×½ºÆ®"; out.println( "<HTML><HEAD><TITLE>" ); out.println( title ); out.println( "</TITLE></HEAD><BODY>" ); out.println( "<H1>" + title + "</H1>" ); out.println( "À¯´ÏÄÚµå ÀÎÄÚµùÀÇ 8859-1¹®ÀÚ: " + "\u00a1\u00a2\u00a3\u00a4" ); out.println( "À¯´ÏÄÚµå ÀÎÄÚµùÀÇ Çö´ë ÇÑ±Û ¹®ÀÚ: " + "\uac00\uac01\uac02\uac03" ); out.println( "</BODY></HTML>" ); out.close(); } } ============ FormServlet.java ============ import java.util.*; import java.io.*; import java.net.*; import javax.servlet.*; import javax.servlet.http.*; public class FormServlet extends HttpServlet { public void doGet( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException { res.setContentType("text/html; charset=euc-kr"); PrintWriter out = new PrintWriter( new OutputStreamWriter(res.getOutputStream(), "KSC5601") ); out.println("<html><head><title>HTML Form Å×½ºÆ®" + "</title></head>"); out.println("<body></h1>" + "HTML Form " + req.getMethod() + " ÀÇ °á°ú: </h1>"); out.println( "À̸§ = " + toHangul(req.getParameterValues("name")[0]) ); out.println( "ÁÖ¼Ò = " + toHangul(req.getParameterValues("address")[0]) ); out.println("</body></html>"); out.close(); } public void doPost( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException { doGet( req, res ); } public static String toHangul( String str ) throws UnsupportedEncodingException { if ( str == null ) return null; return new String( str.getBytes("8859_1"), "KSC5601" ); } }
---
Deogtae Kim (±è´öÅÂ)
CA Lab. CS Dept. KAIST
http://calab.kaist.ac.kr/~dtkim/java