programming/jsp

servlet Post 테스트

labj 2012. 3. 20. 22:04

------------------------------------------

servlet Post 테스트

------------------------------------------

* test.html

<html>
<head>
<title>서블릿테스트</title>
</head>
<boady>
<form method="post" action="servlet/PostTest">
<input type="submit" value="post요청">
</form>
</body>
</html>


 

* PostTest.java

package test;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.text.*;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;

import java.awt.Dimension;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.CategoryLabelPositions;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.CategoryItemRenderer;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;


public class PostTest extends HttpServlet
{
 
    private static CategoryDataset createDataset()
    {
        DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
        defaultcategorydataset.addValue(22000, "PC1", "PC1");
        defaultcategorydataset.addValue(20200, "PC2", "PC2");
        defaultcategorydataset.addValue(21050, "PC3", "PC3");
        defaultcategorydataset.addValue(10200, "PC4", "PC4");
  return defaultcategorydataset;
    }

    private static JFreeChart createChart(CategoryDataset categorydataset)
    {
        JFreeChart jfreechart = ChartFactory.createBarChart3D("", "A-mart", "$", categorydataset, PlotOrientation.VERTICAL, true, true, false);
        CategoryPlot categoryplot = jfreechart.getCategoryPlot();
        CategoryAxis categoryaxis = categoryplot.getDomainAxis();
        categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D));
        CategoryItemRenderer categoryitemrenderer = categoryplot.getRenderer();
        categoryitemrenderer.setItemLabelsVisible(true);
        BarRenderer barrenderer = (BarRenderer)categoryitemrenderer;
        barrenderer.setMaxBarWidth(0.050000000000000003D);
        return jfreechart;
    }

    public static String getDemoDescription()
    {
        return "A bar chart rendered with a '3D effect'.";
    }
 
 
 public void doPost(HttpServletRequest req, HttpServletResponse response) throws ServletException, IOException {
        CategoryDataset categorydataset = createDataset();
        JFreeChart jfreechart = createChart(categorydataset);
  
  response.setContentType("image/jpeg");    
  ServletOutputStream objSos=response.getOutputStream();   
  ChartUtilities.writeChartAsJPEG(objSos,jfreechart,600,400);   
 }
}

 

* web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

  <servlet>
    <servlet-name>invoker</servlet-name>
    <servlet-class>
      org.apache.catalina.servlets.InvokerServlet
    </servlet-class>
    <init-param>
      <param-name>debug</param-name>
      <param-value>0</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>
 
  <servlet-mapping>
    <servlet-name>invoker</servlet-name>
    <url-pattern>/servlet/*</url-pattern>
  </servlet-mapping>
 
  <servlet>
    <servlet-name>PostTest</servlet-name>
    <servlet-class>test.PostTest</servlet-class>
  </servlet>
 
  <servlet-mapping>
    <servlet-name>PostTest</servlet-name>
    <url-pattern>/PostTest</url-pattern>
  </servlet-mapping> 

</web-app>

 

 

 

 

'programming > jsp' 카테고리의 다른 글

HTTP_REFERER  (0) 2012.03.21
동시접속자수, 서버용량, 로드 밸런싱  (0) 2012.03.21
chart  (0) 2012.03.21
css만을 이용한 텍스트 효과  (0) 2012.03.21
servlet test  (0) 2012.03.20