JSP·Î À̹ÌÁö »ý¼ºÇϱâ

kenu
2001-09-11 5:51¿ÀÀü

¾ÖÇø´À¸·Î´Â ±×¸²À» ±×·Á¼­ À¥ºê¶ó¿ìÀú¿¡¼­ º¼ ¼ö ÀÖ¾ú½À´Ï´Ù. ±×·³ JSP ·Î ±×¸²À» ±×¸± ¼ö ÀÖÀ»±î¿ä? Á¤´äÀº YES ÀÔ´Ï´Ù. ÇÏÁö¸¸ Áö±Ý±îÁö´Â No ¿´½À´Ï´Ù. ¾Æ¹«µµ °¡¸£ÃÄÁÖ´Â »ç¶÷ÀÌ ¾ø¾î¿ä. ¾û¾û~ ³ª ¾î¶»ÇØ È¸»ç ÂѰܳª¸é... ¿ì¸® ¾ÆÀÌ ¸ÔÀ» °Í ÀÔÀ» °Í »ç·Á¸é ¾Æ³»°¡ ¹ö´Â µ·¸¸À¸·Î´Â ºÎÁ·Çѵ¥... ´ÙÇàÈ÷ ¸ðÀ¯ ¸ÔÀ¸´Ï±î ¿ìÀ¯°ªÀº ¾Èµå´Âµ¥, Á¾ÀÌ ±âÀú±Í´Â ¾î¶»Ç϶ó±¸... <-- ¾îÁ¦±îÁö ÀúÀÇ ¸ð½ÀÀ̾ú½À´Ï´Ù.

ÇÏÇÏ, ²¨¶±¾ø½¿´Ù. °ÅÀú ¿ºº¯¿¡¼­´Â JSP ·Î ±×¸²±×¸®´Â °ÍÀº jsp Ãà¿¡µµ ¸ø³§´Ï´Ù. ÇìÇì ³ó´ã ±×¸¸Çϰí, ^^ ¼Ò½º °ø°³ÇÕ´Ï´Ù. ¾Æ´Ï, ¹æ¹ýÀ» °ø°³ÇÕ´Ï´Ù.

ÁÖ½ÄÇöȲ ±×·¡ÇÁ³ª, ¹æ¹®Åë°è±×·¡ÇÁ µîÀ» ±×¸± ¼ö ÀÖ½À´Ï´Ù. ÇѰ¡Áö ±â¾ïÇØ¾ß ÇÒ °ÍÀº °ø°³ÇÁ·Î±×·¥À» ³»³õ°í ¸¹Àº »ç¶÷µéÀÇ ¼ö°í¸¦ ´ú¾îÁÖ´Â ¶óÀ̺귯¸® °³¹ßÀڵ鿡°Ô °¨»çÇØ¾ß ÇÑ´Ù´Â °ÍÀÔ´Ï´Ù. java ·Î °ø°³µÈ ¶óÀ̺귯¸® Áß¿¡ www.acme.com ¿¡¼­ ³ª¿Â GifEncoder °¡ °¡Àå À¯¸íÇÕ´Ï´Ù. ÀÌ ¹Û¿¡µµ jclassµµ ÀÖ°í, Àúµµ ¾ËÁö ¸øÇÏ´Â ¿©·¯ °ø°³µÈ ¼Ò½º°¡ ÀÖÀ» °Ì´Ï´Ù. ÀϹÝÀûÀ¸·Î ¸¹ÀÌ ¾²ÀÌ´Â www.acme.com ÆÐŰÁö¸¦ »ç¿ëÇϵµ·Ï ÇϰڽÀ´Ï´Ù.

test ȯ°æÀº Tomcat 3.2.3 °ú windows 2000 professional , ±×¸®°í apache 1.3.20 ÀÔ´Ï´Ù. ¾Æ! jdk´Â 1.3.1_02 ÀÔ´Ï´Ù. ¹öÀüÀÌ ´Þ¶ó¼­ ¾ÈµÇ´Â °æ¿ì´Â... À¸¾Ç~ »ì·ÁÁÖ¼¼¿ä. T.T; °¡´ÉÇÏ¸é ¹öÀü ¸ÂÃç¼­ Å×½ºÆ®Çغ¸¼¼¿ä. Linux/Unix ȯ°æÀÏ °æ¿ì´Â x Window »óÅ¿¡¼­ xhost localhost ¶ó°í ÇØÁà¾ß ÇѴٳ׿ä. ÀÌÂÊÀº ¿ï ȸ»ç SE ¶û ¾ê±â¸¦ ÇØºÁ¾ß°Ú³×¿ä. ÀÏ´Ü À©µµ¿ì¿¡¼­ µ¹¸®´Â °Í¸¸ °¡Á¤ÇϰڽÀ´Ï´Ù.

¼Ò½ºÀÇ Ãâó´Â ÇѺû¹Ìµð¾î¿¡¼­ ³ª¿Â ¼­ºí¸´ÇÁ·Î±×·¡¹Ö Ã¥ÀÔ´Ï´Ù. ¼­ºí¸´ ¼Ò½ºÀε¥, jsp ·Î ¹Ù²Û °Í »ÓÀÔ´Ï´Ù. ¾Æ, ±×Àü¿¡ www.acme.com »çÀÌÆ®¿¡ °¡¼­ ÆÐŰÁö¸¦ ´Ù¿î¹Þ¾Æ¿Í¾ßÁö¿ä. http://www.acme.com/java/software/Acme.JPM.Encoders.GifEncoder.html ÀÔ´Ï´Ù.

GifEncoderÀÇ API °¡ ³ª¿É´Ï´Ù. package Àüü¸¦ ´Ù¿î¹ÞÀ¸µµ µË´Ï´Ù. Fetch the entire ACME package ¸¦ Ŭ¸¯Çϸé ACME ÆÐŰÁö Àüü°¡ gzipÀ¸·Î ¾ÐÃàµÈ °ÍÀ» ´Ù¿î¹ÞÀ» ¼ö ÀÖ½À´Ï´Ù.

´Ù¿î¹ÞÀº Acme.tar.gzÀ» ¾ËÁýÀ» ÀÌ¿ëÇØ¼­ ¾ÐÃàÀ» DZ´Ï´Ù. ÇÊ¿äÇÑ ÆÄÀÏÀÌ, Acme ¶ó´Â µð·ºÅ丮 ¾È¿¡ JPM µð·ºÅ丮°¡ ÀÖ°í ±× ¾È¿¡´Â Encoders ¶ó´Â µð·ºÅ丮°¡ ÀÖ°í ±× ¾È¿¡´Â class ÆÄÀÏÀÌ µÎ°³ ÀÖ½À´Ï´Ù. Acme µð·ºÅ丮¸¦ WEB-INF\classes ¾Æ·¡·Î À̵¿ÇÕ´Ï´Ù. ¾îµòÁö ¾Æ½ÃÁÒ? ¾Æ´Ï¸é Á¦°¡ Tips °Ô½ÃÆÇ¿¡ ¿Ã·Á³õÀº Acme.jar ÆÄÀÏÀ» c:\jdk1.3\jre\lib\ext ¿¡ º¹»ç½ÃÄÑ ³õ¾Æµµ µË´Ï´Ù.

ÀÌÁ¦ ¼³Ä¡´Â ³¡³µ½À´Ï´Ù. ¼Ò½º¸¦ º¸ÁÒ.
imageCall.html
<html>
<body bgcolor="#000000">
<img src="HelloGraphics.jsp">
</body>
</html>
		
HelloGraphics.jsp
<%@ page import="java.io.*, java.awt.*, Acme.JPM.Encoders.GifEncoder"
%><%

    Frame frame = null;
    Graphics g = null;

    try {
      // Create an unshown frame
      frame = new Frame();
      frame.addNotify();

      // Get a graphics region, using the Frame
      Image image = frame.createImage(200, 300); // image size width 200, height 300
      g = image.getGraphics();

g.setFont(new Font("Serif", Font.ITALIC, 50)); 
g.drawString("JSP", 10, 50); 
g.drawString("Image!", 10, 80); 
g.setColor(new Color(0x0080AA)); 
g.setFont(new Font("Garamond", Font.PLAIN, 18)); 
g.drawString("www.okjsp.pe.kr", 60, 280); 

      // Encode the off screen image into a GIF and send it to the client
      response.setContentType("image/gif");
      GifEncoder encoder = new GifEncoder(image, response.getOutputStream());
      encoder.encode();
    }
    finally {
      // Clean up resources
      if (g != null) g.dispose();
      if (frame != null) frame.removeNotify();
    }
%>
		


HelloGraphics.jsp ÆÄÀÏÀº text/html À» »ý¼ºÇØ ³»´Â °ÍÀÌ ¾Æ´Ï¶ó, image/gif Çü½ÄÀÇ ÆÄÀÏÀ» »ý¼ºÇØ ³À´Ï´Ù. ±×·¡¼­ img src="HelloGraphics.jsp" ó·³ È£ÃâÇÒ ¼ö ÀÖ´Â °ÍÀÌÁÒ.

ÇѱÛÀº ¿©±â¼­µµ ÀÎÄÚµùÀ» ÇØÁà¾ß µÇ´Â ±º¿ä. ÀÌ·¸°Ô º¯°æÇØÁÖ½Ã¸é µË´Ï´Ù.

String txt = "ÇѱÛ, Image!";
txt = new String(txt.getBytes("8859_1"),"euc-kr");
g.setFont(new Font("Gulim", Font.ITALIC, 30)); 
g.drawString("JSP", 10, 50); 
g.drawString(txt, 10, 80); 


¿©±â¿¡ °üÇØ¼­ °ü·ÃÀÚ·áµéÀ» ´õ ã¾Æº¸½Ã±â ¹Ù¶ø´Ï´Ù. jpeg »ý¼ºÇÏ´Â ¶óÀ̺귯¸®µµ ÀÖ°í, ´Ù¾çÇÏ°Ô ÀÀ¿ëÇÒ ¼ö ÀÖ°ÚÁÒ. ¿äÁò À¯ÇàÇÏ´Â avatar µµ ¸¸µé ¼ö ÀÖ°ÚÁÒ.

¸¶Áö¸·À¸·Î ¸·´ë±×·¡ÇÁ Çϳª ±×¸®°í ³¡³»µµ·Ï ÇϰڽÀ´Ï´Ù. ¿ø¸®´Â ÀÌ·¸½À´Ï´Ù. ¼ýÀÚµéÀ» ¹è¿­¿¡ ³õ°í ¸Æ½Ã¸Ø °ªÀ» ±¸ÇÕ´Ï´Ù. À̹ÌÁö Å©±â¿¡ ¸ÂÃç¼­ ºñÀ²À» °áÁ¤ÇÕ´Ï´Ù. ¹è¿­ÀÇ length ·Î À̹ÌÁö ÆøÀ» ³ª´¯´Ï´Ù. ±×¸®°í ±×·ÁÁÖ¸é µË´Ï´Ù. ³­¼ö¸¦ 10 °³ ¸¸µé¾î¼­ µ¿ÀûÀ¸·Î À̹ÌÁö¸¦ »ý¼ºÇغ¸µµ·Ï ÇϰڽÀ´Ï´Ù.

HelloGraphics.jsp
<%@ page import="java.util.*, java.io.*, java.awt.*, Acme.JPM.Encoders.GifEncoder"
%><%

// °è»ê
// ³­¼ö ¹ß»ý
	double [] num = new double[10];
	for(int i=0;i<num.length; i++) {
		num[i] = Math.random() * 100;
	}
// ÃÖ´ë°ª
	double max=num[0] ;
	for(int i=1;i<num.length;i++) {
		if(max<num[i])
			max=num[i];
	}
	
	int margin = 10;
	float x_pace = (300-margin*2) / (float)10;
	float y_height = (float)(200-margin*2);
	double ratio = y_height / max;


    Frame frame = null;
    Graphics g = null;

    try {
      // Create an unshown frame
      frame = new Frame();
      frame.addNotify();

      // Get a graphics region, using the Frame
      Image image = frame.createImage(300, 200); // image size width 300, height 200
      g = image.getGraphics();

g.setColor(new Color(0x0040FF)); 
g.setFont(new Font("System", Font.PLAIN, 11)); 
g.drawString("www.okjsp.pe.kr", 210, 198); 
g.drawString("Max:"+max, 10, 198); 

// draw Bars
int xx = 0;
int yy = 0;

g.setColor(new Color(0x000000)); 
g.drawRect(0,0,299,199);
for (int i=0; i<num.length; i++) {
	xx = (int)(i * x_pace) + margin;
	yy = (int)(num[i] * ratio);
	yy = 200 - (yy + margin); 
	
	g.drawRect(xx, yy, (int)x_pace-3, 188 - yy);
	g.drawString(""+(int)num[i], xx+9, yy);
}

      // Encode the off screen image into a GIF and send it to the client
      response.setContentType("image/gif");
      GifEncoder encoder = new GifEncoder(image, response.getOutputStream());
      encoder.encode();
    }
    finally {
      // Clean up resources
      if (g != null) g.dispose();
      if (frame != null) frame.removeNotify();
    }
%>


¿À´Ã °­Á°¡ ¸¹Àº µµ¿òÀÌ µÇ±æ ¹Ù¶ø´Ï´Ù. ¹ãÀ» »õ¹ö·È³×¿ä. ³»ÀÏ È¸»ç°¡¼­ Á¹Áö³ª ¾ÊÀ»·¡³ª....

°ü·Ã »çÀÌÆ®
¡áhttp://www.acme.com/
°­Á¿¡¼­ ¼Ò°³ÇÑ »çÀÌÆ®ÀÔ´Ï´Ù.
¡áhttp://www.acme.com/java/software/Acme.JPM.Encoders.GifEncoder.html
´Ù¿î¹ÞÀ» ¼ö ÀÖ´Â °÷ÀÔ´Ï´Ù.
¡áhttp://www.4offline.org/bbs/view.php?id=Tip&page=1&page_num=20&category=&sn=off&ss=off&sc=off&keyword=&select_arrange=headnum&desc=asc&no=33
4offline : [JSP] À̹ÌÁö ¸¸µé¾î¼­ È­¸é¿¡ »Ñ¸®±â.
xml-typed document
http://okjsp.pe.kr