package demo;
import javax.servlet.http.*;
import com.trulytech.mantis.system.*;
import com.trulytech.mantis.result.*;
import com.trulytech.mantis.util.Chart;
import com.trulytech.mantis.util.StringUtils;
import java.awt.Color;
import java.awt.Font;
/**
* <p>
* Title:
* </p>
* <p>
* Description:
* </p>
* <p>
* Copyright: Copyright (c) 2002
* </p>
* <p>
* Company:
* </p>
*
* @author Wang Xian
* @version 1.2
*/
public class ImageServlet extends ActionServlet {
// Process the HTTP Get request
protected String PerformGet(HttpServletRequest request,
HttpServletResponse response, SQLParser Parser) throws Exception
{
// 绘制字符串
if (getParameter(request, "Action").equalsIgnoreCase("String")) {
Chart chart = new Chart(response, 200, Color.BLUE, Color.yellow, 3);
chart.setStr(getParameter(request, "str"));
return chart.drawChart();
}
// 绘制校验码
else if (getParameter(request, "Action").equalsIgnoreCase("randimg")) {
Chart chart = new Chart(response, 50, null, null, 3);
chart.setStrfont(new Font("Times New Roman", 0, 18));
chart.setStr(StringUtils.randomNumber(4));
return chart.drawChart();
} else { // 绘制饼图
Chart chart = new Chart(response, 400, Color.white, Color.black, 0);
DBResult Result = Parser
.QueryExecute("select label,value from piechart order by id desc");
chart.setResult(Result);
chart.setBKColor(Color.white);
chart.setLabelValue("label");
chart.setValueName("value");
chart.setFill(Color.red);
return chart.drawChart();
}
}
// 重载身份校验函数
protected int HasPermission(HttpServletRequest request,
HttpServletResponse response, SQLParser Parser) throws Exception {
return Permission.ALLOW;
}
protected String PerformPost(HttpServletRequest request,
HttpServletResponse response, SQLParser Parser) throws Exception {
return PerformGet(request, response, Parser);
}
}