锘??xml version="1.0" encoding="utf-8" standalone="yes"?> String url="http://10.58.2.131:8088/spesBiz/test1.jsp"; try {
String cmd = "cmd.exe /c start " + url;
Process proc = Runtime.getRuntime().exec(cmd);
proc.waitFor();
}
catch (Exception e)
{
e.printStackTrace();
}
URLConnection connection = U.openConnection();
connection.connect();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = in.readLine())!= null)
{
result += line;
}
in.close();
]]>
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import sun.net.TelnetOutputStream;
import sun.net.ftp.FtpClient;
import com.baosight.dexpt.DefaultDispatcher;
public class FtpSender {
private FtpClient ftpClient;
private String ftpName="";
private String ftpPassword="";
private String ftpIp="";
private String ftpPath="";
private String localPath;
public void init()
{
Properties props=new Properties();
Class clazz=DefaultDispatcher.class;
ClassLoader clazzLoader=clazz.getClassLoader();
InputStream is=null;
is=clazzLoader.getResourceAsStream("dominoAttach.properties");
try{
props.load(is);
this.ftpIp=props.getProperty("ftp_ip");
this.ftpName = props.getProperty("ftp_name");
this.ftpPassword = props.getProperty("ftp_password");
this.ftpPath = props.getProperty("ftp_path");
this.localPath = props.getProperty("path");
}
catch(Exception e)
{
e.printStackTrace();
}
finally{
if(is!=null)
{
try{
is.close();
}catch(IOException e)
{
e.printStackTrace();
}
}
}
}
private void connectServer() throws IOException
{
ftpClient = new FTPClient();
ftpClient.connect(this.ftpIp);
boolean blogin = ftpClient.login(this.ftpName, this.ftpPassword);
if(!blogin)
{
System.out.println("榪炴帴澶辮觸");
ftpClient.disconnect();
ftpClient = null;
}
}
public void closeConnect(){
try{
if(ftpClient!=null){
ftpClient.logout();
ftpClient.disconnect();
}
}catch(Exception e){
e.printStackTrace();
}
}
private String upload(String filename) throws Exception
{
InputStream is = null;
try
{
is = new FileInputStream(new File(this.localPath+filename));
this.ftpClient.storeFile(this.ftpPath+"/"+filename, is);
} catch(Exception e)
{
e.printStackTrace();
}
return "file send success!";
}
public boolean sendFtpFile(String filename)
{
try
{
init();
connectServer();
String ret = upload(filename);
System.out.println("---------ret:"+ret);
closeConnect();
} catch (Exception e)
{
e.printStackTrace();
}
return true;
}
/*********
* 璇誨彇domino FTP閲岀殑闄勪歡錛屽茍鎻掑叆db2鍒版暟鎹簱涓?br />
*
*/
public void readDominoFtp(String fileguid)
{
FTPFile[] files = null;
String filename ="";
try
{
this.readinit();
this.connectServer();
FTPListParseEngine engine = this.ftpClient.initiateListParsing(this.ftpPath);
files = engine.getFiles();
//files = this.ftpClient.listFiles(this.ftpPath);
for(int i=0;i<files.length;i++)
{
FTPFile file = files[i];
//filename = iso8859togbk(file.getName());
filename = file.getName();
if(filename.indexOf(fileguid)>=0)
{
this.download(filename);
System.out.println("--filename:"+filename);
this.saveFileToDb(iso8859togbk(filename));
//this.deleteLocalFile();
this.ftpClient.deleteFile(this.ftpPath+"/"+iso8859togbk(filename));
}
}
//closeConnect();
} catch (Exception e)
{
e.printStackTrace();
}
}
private static String iso8859togbk(Object obj){
try{
if(obj==null)
return "";
else
return new String(obj.toString().getBytes("iso-8859-1"),"gbk");
}catch(Exception e){
return "";
}
}
public void download(String filename)
{
BufferedOutputStream fos = null;
try
{
File outFile = new File(this.localPath);
if(!outFile.exists()){
outFile.mkdirs();
}
fos = new BufferedOutputStream (new FileOutputStream(this.localPath+iso8859togbk(filename)));
this.ftpClient.retrieveFile(this.ftpPath+"/"+filename,fos);
}catch(Exception e)
{
e.printStackTrace();
}finally{
try{
if(fos!=null)
fos.close();
}catch(Exception e){
e.printStackTrace();
}
}
}
import java.io.StringBufferInputStream;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.beanutils.PropertyUtils;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class BeanXml
{
/*
* 鐢ㄤ簬 genenateXml()鏂規硶
* 浠庡璞′腑寰楀埌鍊鹼紝浠ョ敓鎴恱ml
*/
public String getFieldValue(Object objValue )
{
StringBuffer valuebuf = new StringBuffer();
if(objValue.getClass().isArray())
{
String [] valueArr = (String[])objValue;
for(int j=0;j<valueArr.length;j++)
{
valuebuf.append("<value>"+valueArr[j]+"</value>");
}
}
if(objValue instanceof java.util.List)
{
List list = (List)objValue;
for(int j=0;j<list.size();j++)
{
valuebuf.append("<value>"+list.get(j)+"</value>");
}
}
else if (objValue instanceof java.util.Date)
{
java.util.Date valueDate = (java.util.Date)objValue;
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
valuebuf.append("<value>"+ formatter.format(valueDate)+"</value>");
}
else if (objValue instanceof String )
{
valuebuf.append("<value>"+objValue+"</value>");
}
else if(objValue instanceof Integer)
{
valuebuf.append("<value>"+objValue+"</value>");
}
else if(objValue instanceof Double)
{
valuebuf.append("<value>"+objValue+"</value>");
}
else if(objValue instanceof Float)
{
valuebuf.append("<value>"+objValue+"</value>");
}
return valuebuf.toString();
}
/*
* 鐢ㄤ簬generateBean鏂規硶
* 鍔熻兘錛氫粠xml涓彇鍊鹼紝緇欏璞¤祴鍊?br> */
public Object getFieldValue(Object object,String name,List valuelist)
{
Object objValue=null;
Object objType =null;
String fieldname ="";
Class cls = object.getClass();
Field[] fields = cls.getDeclaredFields();
try
{
for(int i=0;i<fields.length;i++)
{
fieldname = fields[i].getName();
if(name.equals(fieldname))
{
objType = PropertyUtils.getProperty(object, name);
objValue = getValueByType(objType,valuelist);
return objValue;
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
return "";
}
public Object getValueByType(Object objType,List valuelist)
{
Object objValue=null;
try
{
if(objType.getClass().isArray())
{
String[] arr=null;
for(int i=0;i<valuelist.size();i++)
{
arr=new String[valuelist.size()];
arr[i]=(String)valuelist.get(i);
}
objValue = arr;
}
else if (objType instanceof java.util.List)
{
objValue = valuelist;
}
else if (objType instanceof java.util.Date)
{
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
formatter.applyPattern("yyyyMMdd");
objValue = formatter.parse((String)valuelist.get(0));
}
else if (objType instanceof String )
{
objValue = (String)valuelist.get(0);
}
else if(objType instanceof Integer)
{
objValue = Integer.valueOf((String)valuelist.get(0));
}
else if(objType instanceof Double)
{
objValue = Double.valueOf((String)valuelist.get(0));
}
else if(objType instanceof Float)
{
objValue = Float.valueOf((String)valuelist.get(0));
}
}
catch(Exception e)
{
e.printStackTrace();
}
return objValue;
}
/**
* 鐢熸垚xml
*/
public String generateXML(Object object)
{
Class cls = object.getClass();
Field[] fields = cls.getDeclaredFields();
String name= "";
String type ="";
String value ="";
StringBuffer buf =new StringBuffer();
buf.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
buf.append("<package>");
buf.append("<classname>"+cls+"</classname>");
try
{
for(int i=0;i<fields.length;i++)
{
name = fields[i].getName();
Object objValue = PropertyUtils.getProperty(object, name);
type = PropertyUtils.getPropertyType(object, name).getName();
value = getFieldValue(objValue);
buf.append("<"+name+">");
buf.append("<property>"+type+"</property>");
buf.append("<values>"+value+"</values>");
buf.append("</"+name+">");
}
buf.append("</package>");
}catch(Exception e)
{
e.printStackTrace();
}
return buf.toString();
}
/*
* 鐢熸垚bean
*/
public Object generateBean(String strXML)
{
String name ="";
String type ="";
List elemlist = new ArrayList();
Object objValue;
String classname ="";
Object object =null;
try
{
SAXReader reader = new SAXReader();
StringBufferInputStream is=new StringBufferInputStream(strXML);
Document document = reader.read(is);
Element root = document.getRootElement();
Iterator iter = root.elementIterator();
if(iter.hasNext())
{
classname = ((Element)iter.next()).getTextTrim();
if(classname.indexOf(" ")>0)
classname = classname.substring(classname.lastIndexOf(" ")+1);
object =Class.forName(classname).newInstance();
for( ;iter.hasNext();)
{
Element element = (Element) iter.next();
name = element.getName();
type = (element.element("property")).getTextTrim();
elemlist = element.element("values").elements();
List valuelist = new ArrayList();
for(int j=0;j<elemlist.size();j++)
{
Element subelement = (Element)elemlist.get(j);
valuelist.add(subelement.getTextTrim());
}
objValue = getFieldValue(object,name,valuelist);
PropertyUtils.setProperty(object, name, objValue);
}
}
}catch(Exception e)
{
e.printStackTrace();
}
return object;
}
public static void main(String[] args)
{
try
{
TestBean tb = new TestBean();
String [] str = {"123","23"};
String strxml="";
List list =new ArrayList();
list.add("list111");
list.add("list222");
list.add("list333");
tb.id =123;
tb.setId(123);
tb.setName("abced");
tb.setDate(new java.util.Date());
tb.setArrId(str);
tb.setList(list);
BeanXml bx = new BeanXml();
System.out.println("-------xmlvalue:"+bx.generateXML(tb));
strxml = bx.generateXML(tb);
TestBean testb=(TestBean)bx.generateBean(strxml);
//bx.generateBean(strxml);
System.out.println("-------id:"+testb.getId());
System.out.println("-------name:"+testb.getName());
System.out.println("-------date:"+testb.getDate());
System.out.println("-------arrid"+testb.getArrId()[1]);
System.out.println("-------list:"+testb.getList().get(2));
}catch(Exception e)
{
e.printStackTrace();
}
}
}
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeUtility;
import sun.misc.BASE64Encoder;
import com.baosight.dexpt.DefaultDispatcher;
public class MailSender {
private Map mailMap = new HashMap();
public void init()throws IOException
{
Properties props=new Properties();
Class clazz=DefaultDispatcher.class;
ClassLoader clazzLoader=clazz.getClassLoader();
InputStream is=null;
try
{
is=clazzLoader.getResourceAsStream("mail.properties");
if(is==null)
{
throw new FileNotFoundException("\"classpath:mail.properties\" file not found...or open error...");
}
props.load(is);
}
finally
{
if(is!=null)
is.close();
}
Iterator iter = props.keySet().iterator();
for (; iter.hasNext();)
{
String key = (String) iter.next();
String value=props.getProperty(key);
this.mailMap.put(key, value);
}
}
/***
*
* @param to : 鐩爣閭歡鍦板潃
* @param title :閭歡鏍囬
* @param content: 閭歡鍐呭
* @return 錛氬彂閫佹垚鍔熻繑鍥?錛屽惁鍒欒繑鍥?
*/
public int sendMessage(String to,String title,String content)
{
return sendMessage(to,title,content,null);
}
/***
*
* @param to : 鐩爣閭歡鍦板潃
* @param title :閭歡鏍囬
* @param content: 閭歡鍐呭
* @param map :key涓烘枃浠剁殑鍚嶅瓧錛寁alue涓烘枃浠舵祦錛圛nputstream錛?br> * @return 錛氬彂閫佹垚鍔熻繑鍥?錛屽惁鍒欒繑鍥?
*/
public int sendMessage(String to,String title,String content,HashMap map)
{
String [] tt = {to};
return sendMessage(tt,null,title,content,map);
}
/***
*
* @param to : 鐩爣閭歡鍦板潃
* @param cc : 鎶勯侀偖浠跺湴鍧
* @param title :閭歡鏍囬
* @param content: 閭歡鍐呭
* @param map :key涓烘枃浠剁殑鍚嶅瓧錛寁alue涓烘枃浠舵祦錛圛nputstream錛?br> * @return 錛氬彂閫佹垚鍔熻繑鍥?錛屽惁鍒欒繑鍥?
*/
public int sendMessage(String to,String cc,String title,String content,HashMap map)
{
String [] ttArr = {to};
String [] ccArr={cc};
return sendMessage(ttArr,ccArr,title,content,map);
}
/***
*
* @param to : 鐩爣閭歡鍦板潃鏁扮粍
* @param cc : 鎶勯侀偖浠跺湴鍧鏁扮粍
* @param title :閭歡鏍囬
* @param content: 閭歡鍐呭
* @param map :key涓烘枃浠剁殑鍚嶅瓧錛寁alue涓烘枃浠舵祦錛圛nputstream錛?br> * @return 錛氬彂閫佹垚鍔熻繑鍥?錛屽惁鍒欒繑鍥?
*/
public int sendMessage(String[] to,String cc[],String title,String content,HashMap map)
{
String host = (String)mailMap.get("host");
String from = (String)mailMap.get("from");
String username = (String)mailMap.get("user");
String password = (String)mailMap.get("password");
BASE64Encoder enc = new BASE64Encoder();
try
{
Properties props = new Properties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
Session session = Session.getDefaultInstance(props);
session.setDebug(true);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
InternetAddress[] sendTo = new InternetAddress[to.length];
InternetAddress[] sendCc = new InternetAddress[cc.length];
for (int i = 0; i < to.length; i++)
{
sendTo[i] = new InternetAddress(to[i]);
}
for (int i = 0; i < cc.length; i++)
{
sendCc[i] = new InternetAddress(cc[i]);
}
message.addRecipients(Message.RecipientType.TO,sendTo);
message.addRecipients(Message.RecipientType.CC,sendCc);
message.setSubject(title);
//attachment
MimeMultipart multi = new MimeMultipart();
MimeBodyPart textBodyPart = new MimeBodyPart();
textBodyPart.setContent(content, "text/html;charset=GBK");
multi.addBodyPart(textBodyPart);
Iterator iter = map.keySet().iterator();
for(;iter.hasNext();)
{
String filename = ""+iter.next();
InputStream is = (InputStream)map.get(filename);
MimeBodyPart fileBodyPart = new MimeBodyPart();
DataHandler dh = new DataHandler(new ByteArrayDataSource(is,"application/octet-stream"));
fileBodyPart.setDataHandler(dh);
fileBodyPart.setFileName(MimeUtility.encodeText(filename));
multi.addBodyPart(fileBodyPart);
}
message.setContent(multi);
message.saveChanges();
Transport transport = session.getTransport("smtp");
transport.connect(host, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
}catch(Exception e)
{
e.printStackTrace();
}
return 1;
}
/**
* @param args
*/
public static void main(String[] args)
{
MailSender ms = new MailSender();
String[] to = {"hobby8062@yahoo.com.cn","hobby8052@163.com"};
String[] cc = {"hobby8052@yahoo.com.cn"};
String title ="嫻嬭瘯";
String content="嫻嬭瘯<br><a ;
//String content="嫻嬭瘯";
try
{
ms.init();
HashMap map = new HashMap();
InputStream is = new BufferedInputStream( new FileInputStream("e:/嫻嬭瘯.doc"));
String tostr = "hobby8052@163.com";
map.put("嫻嬭瘯.doc", is);
is = new BufferedInputStream( new FileInputStream("e:/嫻嬭瘯.rar"));
map.put("嫻嬭瘯.rar", is);
ms.sendMessage(to, cc, title, content, map);
//ms.sendMessage(tostr, title, content, map);
}catch(Exception e)
{
e.printStackTrace();
}
}
}
/*************************瀵歸檮浠舵祦錛坕nputstream錛夌殑澶勭悊***************************************/
package com.baosight.spes.mail;
//Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
//Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
//Decompiler options: packimports(3) fieldsfirst ansi
//Source File Name: ByteArrayDataSource.java
import java.io.*;
import javax.activation.DataSource;
public class ByteArrayDataSource
implements DataSource
{
private byte data[];
private String type;
public ByteArrayDataSource(InputStream inputstream, String s)
{
type = s;
try
{
ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
byte abyte0[] = new byte[4096];
for(int i = 0; (i = inputstream.read(abyte0)) != -1;)
{
bytearrayoutputstream.write(abyte0, 0, i);
}
data = bytearrayoutputstream.toByteArray();
}
catch(IOException ioexception)
{
ioexception.printStackTrace();
}
}
public ByteArrayDataSource(byte abyte0[], String s)
{
data = abyte0;
type = s;
}
public ByteArrayDataSource(String s, String s1)
{
data = s.getBytes();
type = s1;
}
public InputStream getInputStream()
throws IOException
{
if(data == null)
throw new IOException("no data");
else
return new ByteArrayInputStream(data);
}
public OutputStream getOutputStream()
throws IOException
{
throw new IOException("cannot do this");
}
public String getContentType()
{
return type;
}
public String getName()
{
return "dummy";
}
}
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Font;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Date;
import javax.servlet.http.HttpSession;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.labels.StandardPieItemLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.CategoryDataset;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.time.Minute;
import org.jfree.data.time.TimePeriodValues;
import org.jfree.data.time.TimePeriodValuesCollection;
import org.jfree.data.xy.XYDataset;
public class ChartExample {
/*****
* 鐢熸垚鏌卞艦鍥劇殑瀹炰緥錛屼繚瀛樺埌Jpg鏂囦歡涓?br> */
public void createChar3D()
{
CategoryDataset dataset = getDataSet2();
JFreeChart chart = ChartFactory.createBarChart3D(
"姘存灉浜ч噺鍥?, // 鍥捐〃鏍囬
"姘存灉", // 鐩綍杞寸殑鏄劇ず鏍囩
"浜ч噺", // 鏁板艱醬鐨勬樉紺烘爣絳?nbsp;
dataset, // 鏁版嵁闆?nbsp;
PlotOrientation.VERTICAL, // 鍥捐〃鏂瑰悜錛氭按騫熾佸瀭鐩?nbsp;
true, // 鏄惁鏄劇ず鍥句緥(瀵逛簬綆鍗曠殑鏌辯姸鍥懼繀欏繪槸false)
false, // 鏄惁鐢熸垚宸ュ叿
false // 鏄惁鐢熸垚URL閾炬帴
);
FileOutputStream fos_jpg = null;
try
{
fos_jpg = new FileOutputStream("e:/123.jpg");
ChartUtilities.writeChartAsJPEG(fos_jpg,0.8f,chart,400,300);
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
fos_jpg.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
}
/**
* 鑾峰彇涓涓紨紺虹敤鐨勭粍鍚堟暟鎹泦瀵硅薄 錛堟煴褰㈠浘錛?br> * @return
*/
private static CategoryDataset getDataSet2()
{
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
dataset.addValue(100, "鍖椾含", "鑻規灉");
dataset.addValue(100, "涓婃搗", "鑻規灉");
dataset.addValue(100, "騫垮窞", "鑻規灉");
dataset.addValue(200, "鍖椾含", "姊ㄥ瓙");
dataset.addValue(200, "涓婃搗", "姊ㄥ瓙");
dataset.addValue(200, "騫垮窞", "姊ㄥ瓙");
dataset.addValue(300, "鍖椾含", "钁¤悇");
dataset.addValue(300, "涓婃搗", "钁¤悇");
dataset.addValue(300, "騫垮窞", "钁¤悇");
dataset.addValue(400, "鍖椾含", "棣欒晧");
dataset.addValue(400, "涓婃搗", "棣欒晧");
dataset.addValue(400, "騫垮窞", "棣欒晧");
dataset.addValue(500, "鍖椾含", "鑽旀灊");
dataset.addValue(500, "涓婃搗", "鑽旀灊");
dataset.addValue(500, "騫垮窞", "鑽旀灊");
return dataset;
}
/***
* 鏍規嵁鏃墮棿鐢熸垚鏇茬嚎鍥撅紝淇濆瓨鍒癹pg涓?br> *
*/
public static void createTimeChart()
{
XYDataset xydataset = createDataset();
JFreeChart chart = ChartFactory.createTimeSeriesChart(
"nihao",
"hello",
"123",
xydataset,
true,
true,
true);
FileOutputStream fos_jpg = null;
try
{
fos_jpg = new FileOutputStream("e:/123.jpg");
ChartUtilities.writeChartAsJPEG(fos_jpg,0.8f,chart,400,300);
}catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
fos_jpg.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
}
/****
* 鑾峰彇涓涓紨紺虹敤鐨勭粍鍚堟暟鎹泦瀵硅薄 錛堟椂闂存洸綰垮浘錛?br> * @return
*/
private static XYDataset createDataset()
{
TimePeriodValues timeseries1 = new TimePeriodValues("Chart Title");
//榪欏湴鏂瑰彲浠ヤ嬌鐢ㄥ驚鐜紝鎶妜杞達紝y杞?nbsp; 鐨勫?nbsp; 杈呯粰timeseries1
TimePeriodValuesCollection timeseriescollection = new TimePeriodValuesCollection();
for(int i =1;i<10;i++)
{
Minute min = new Minute(new Date());
timeseries1.add(min, i);
timeseriescollection.addSeries(timeseries1);
}
return timeseriescollection;
}
/***********楗肩姸鍥?********/
private DefaultPieDataset data =new DefaultPieDataset();
private Font titleFont = new Font("榛戜綋",Font.CENTER_BASELINE,18);
/****
* 璁劇疆涓涓紨紺虹敤鐨勭粍鍚堟暟鎹泦瀵硅薄 錛堥ゼ鐘跺浘錛?br> * @return
*/
public void setValue(String key,double value)
{
data.setValue(key,value);
}
/***
* 鏍規嵁鏃墮棿鐢熸垚鐥呯姸鍥撅紝鏄劇ず鍒癹sp欏甸潰
*
*/
public String generatePieChart(String title, HttpSession session, PrintWriter pw)
{
String filename = null;
String unitSytle = "{0}={1}({2})";
try {
JFreeChart chart = ChartFactory.createPieChart3D("楗煎瀷鍥?, // chart title
data, // data
true, // include legend
true,
false
);
//璁劇疆鍥劇墖鐨勮儗鏅壊
chart.setBackgroundPaint(new Color(215,215,215));
//璁劇疆閫忔槑搴︼紝濂藉儚瀵箂ervlet娌℃湁鐢?br> chart.setBackgroundImageAlpha(0.9f);
//璁劇疆鍥劇墖鏍囬鐨勫瓧浣撳拰澶у皬
TextTitle _title = new TextTitle(title);
_title.setFont(titleFont);
chart.setTitle(_title);
PiePlot plot = (PiePlot) chart.getPlot();
plot.setNoDataMessage("鏃犲搴旂殑鏁版嵁錛岃閲嶆柊鏌ヨ銆?);
plot.setNoDataMessagePaint(Color.red);
//鎸囧畾 section 杞粨綰跨殑鍘氬害(OutlinePaint涓嶈兘涓簄ull)
plot.setOutlineStroke(new BasicStroke(0));
//璁劇疆絎竴涓?section 鐨勫紑濮嬩綅緗紝榛樿鏄?2鐐歸挓鏂瑰悜
plot.setStartAngle(90);
plot.setToolTipGenerator(new StandardPieItemLabelGenerator(unitSytle,
NumberFormat.getNumberInstance(),
new DecimalFormat("0.00%")));
//鎸囧畾鍥劇墖鐨勯忔槑搴?br> plot.setForegroundAlpha(0.65f);
//寮曞嚭鏍囩鏄劇ず鏍峰紡
plot.setLabelGenerator(new StandardPieItemLabelGenerator(unitSytle,
NumberFormat.getNumberInstance(),
new DecimalFormat("0.00%")));
//鍥句緥鏄劇ず鏍峰紡
plot.setLegendLabelGenerator(new StandardPieItemLabelGenerator(unitSytle,
NumberFormat.getNumberInstance(),
new DecimalFormat("0.00%")));
//鎶婄敓鎴愮殑鍥劇墖鏀懼埌涓存椂鐩綍
ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
//璁劇疆鍥劇墖鍚嶇О鍓嶇紑
ServletUtilities.setTempFilePrefix("chart-");
//500鏄浘鐗囬暱搴︼紝300鏄浘鐗囬珮搴?br> filename = ServletUtilities.saveChartAsPNG(chart, 500, 300, info, session);
ChartUtilities.writeImageMap(pw, filename, info, false);
pw.flush();
System.out.println(System.getProperty("java.io.tmpdir") + filename);
} catch (Exception e) {
System.out.println("Exception - " + e.toString());
e.printStackTrace(System.out);
filename = "public_error_600x350.png";
}
return filename;
}
/**
* @param args
*/
public static void main(String[] args)
{
createTimeChart();
}
}
/**************************楗煎艦鍥劇殑jsp欏甸潰***************************************/
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import ="java.io.PrintWriter" %>
<%@ page import="com.chart.ChartExample"%>
<%
ChartExample chart = new ChartExample();
chart.setValue("鍏湀",500);
chart.setValue("涓冩湀",580);
chart.setValue("鍏湀",828);
String filename = chart.generatePieChart("www.SenTom.net 緗戠珯璁塊棶緇熻琛?,session, new PrintWriter(out));
String graphURL = request.getContextPath() +"/servlet/DisplayChart?filename=" + filename;
%>
<HTML>
<HEAD>
<TITLE>www.sentom.net</TITLE>
</HEAD>
<BODY>
<P ALIGN="CENTER">
<img src="<%= graphURL %>" width=500 height=300 border=0 usemap="#<%=filename%>"></P>
</BODY>
</HTML>
聽聽聽for(int i=0;i<list.size();i++)
聽聽聽{
聽聽聽聽e=(Element)list.get(i);
聽聽聽聽sPropName=e.getName();
聽聽聽聽sPropValue=e.getTextTrim();
聽聽聽聽hm.put(sPropName,sPropValue);
聽聽聽聽hashmap.put(index+i,hm);
聽聽聽聽hashmap.putAll(getElements(index+i,e));聽聽聽聽聽
聽聽聽}
聽聽聽
聽聽}
聽聽catch(Exception e)
聽聽{
聽聽}
聽聽return hashmap;
聽}
聽public static HashMap getElements(String index ,Element e)
聽{
聽聽HashMap hm = new HashMap();
聽聽HashMap hashmap = new HashMap();
聽聽List list =e.elements();
聽聽Element temp;
聽聽String sName="";
聽聽String sValue="";
聽聽for (int i=0;i<list.size();i++)
聽聽{
聽聽聽temp=(Element)list.get(i);
聽聽聽sName=temp.getName();
聽聽聽sValue=temp.getTextTrim();
聽聽聽hm.put(sName,sValue);
聽聽聽hashmap.put(index+i,hm);
聽聽聽if(temp.elements().size()>0)
聽聽聽聽hashmap.putAll(getElements(index+i,temp));
聽聽}
聽聽return hashmap;
聽}
//聽聽涓浜涗復鏃跺彉閲忥紝鐢ㄤ簬鍐欏埌excel涓?br />聽聽Label l=null;
聽聽jxl.write.Number n=null;
聽聽jxl.write.DateTime d=null;
//聽聽棰勫畾涔夌殑涓浜涘瓧浣撳拰鏍煎紡錛屽悓涓涓狤xcel涓渶濂戒笉瑕佹湁澶鏍煎紡
聽聽WritableFont headerFont = new WritableFont(WritableFont.ARIAL, 12, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLUE);
聽聽WritableCellFormat headerFormat = new WritableCellFormat (headerFont);
聽聽WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.RED);
聽聽WritableCellFormat titleFormat = new WritableCellFormat (titleFont);
聽聽WritableFont detFont = new WritableFont(WritableFont.ARIAL, 10, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK);
聽聽WritableCellFormat detFormat = new WritableCellFormat (detFont);
聽聽NumberFormat nf=new NumberFormat("0.00000");聽 //鐢ㄤ簬Number鐨勬牸寮?br />聽聽WritableCellFormat priceFormat = new WritableCellFormat (detFont, nf);
聽聽DateFormat df=new DateFormat("yyyy-MM-dd");//鐢ㄤ簬鏃ユ湡鐨?br />聽聽WritableCellFormat dateFormat = new WritableCellFormat (detFont, df);
//聽聽鍓╀笅鐨勪簨鎯咃紝灝辨槸鐢ㄤ笂闈㈢殑鍐呭鍜屾牸寮忓垱寤轟竴浜涘崟鍏冩牸錛屽啀鍔犲埌sheet涓?br />聽聽l=new Label(0, 0, "鐢ㄤ簬嫻嬭瘯鐨凟xcel鏂囦歡", headerFormat);
聽聽sheet.addCell(l);
//聽聽add Title
聽聽int column=0;
聽聽l=new Label(column++, 2, "鏍囬", titleFormat);
聽聽sheet.addCell(l);
聽聽l=new Label(column++, 2, "鏃ユ湡", titleFormat);
聽聽sheet.addCell(l);
聽聽l=new Label(column++, 2, "璐у竵", titleFormat);
聽聽sheet.addCell(l);
聽聽l=new Label(column++, 2, "浠鋒牸", titleFormat);
聽聽sheet.addCell(l);
//聽聽add detail
聽聽int i=0;
聽聽column=0;
聽聽l=new Label(column++, i+3, "鏍囬 "+i, detFormat);
聽聽sheet.addCell(l);
聽聽d=new DateTime(column++, i+3, new java.util.Date(), dateFormat);
聽聽sheet.addCell(d);
聽聽l=new Label(column++, i+3, "CNY", detFormat);
聽聽sheet.addCell(l);
聽聽n=new jxl.write.Number(column++, i+3, 5.678, priceFormat);
聽聽sheet.addCell(n);
聽聽i++;
聽聽column=0;
聽聽l=new Label(column++, i+3, "鏍囬 "+i, detFormat);
聽聽sheet.addCell(l);
聽聽d=new DateTime(column++, i+3, new java.util.Date(), dateFormat);
聽聽sheet.addCell(d);
聽聽l=new Label(column++, i+3, "SGD", detFormat);
聽聽sheet.addCell(l);
聽聽n=new jxl.write.Number(column++, i+3, 98832, priceFormat);
聽聽sheet.addCell(n);
//聽聽璁劇疆鍒楃殑瀹藉害
聽聽column=0;
聽聽sheet.setColumnView(column++, 20);
聽聽sheet.setColumnView(column++, 20);
聽聽sheet.setColumnView(column++, 10);
聽聽sheet.setColumnView(column++, 20);
聽聽workbook.write();
聽聽workbook.close();
聽}
聽public static ArrayList readXLS() throws Exception
聽{
聽聽Workbook workbook = null;
聽聽ArrayList list = new ArrayList();
聽聽
聽聽try {
聽聽聽聽 workbook = Workbook.getWorkbook(new File("d:\\test.xls"));
聽聽} catch (Exception e) {
聽聽聽聽 throw new Exception("file to import not found!");
聽聽}
聽聽Sheet sheet = workbook.getSheet(0);
聽聽Cell cell = null;
聽聽int columnCount=8;
聽聽int rowCount=sheet.getRows();
聽聽for (int i = 1; i <rowCount; i++) {
聽聽聽ArrayList sublist =new ArrayList();
聽聽聽聽 for (int j = 0; j <columnCount; j++) {
聽聽聽聽聽聽聽聽 //娉ㄦ剰錛岃繖閲岀殑涓や釜鍙傛暟錛岀涓涓槸琛ㄧず鍒楃殑錛岀浜屾墠琛ㄧず琛?br />聽聽聽聽聽聽聽聽 cell=sheet.getCell(j, i);
聽聽聽聽聽聽聽聽 //瑕佹牴鎹崟鍏冩牸鐨勭被鍨嬪垎鍒仛澶勭悊錛屽惁鍒欐牸寮忓寲榪囩殑鍐呭鍙兘浼氫笉姝g‘
聽聽聽聽聽聽聽聽 /*
聽聽聽聽聽聽聽聽 if(cell.getType()==CellType.NUMBER){
聽聽聽聽聽聽聽聽聽聽聽聽 System.out.print(((NumberCell)cell).getValue());
聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽 else if(cell.getType()==CellType.DATE){
聽聽聽聽聽聽聽聽聽聽聽聽 System.out.print(((DateCell)cell).getDate());
聽聽聽聽聽聽聽聽 }
聽聽聽聽聽聽聽聽 else{
聽聽聽聽聽聽聽聽聽聽聽聽 System.out.print(cell.getContents());
聽聽聽聽聽聽聽聽 }聽聽
聽聽聽聽聽聽聽聽 ***/聽聽聽聽聽
聽聽聽聽聽聽聽聽 sublist.add(cell.getContents());
聽聽聽聽 }
聽聽聽聽 list.add(sublist);
聽聽}
聽聽//鍏抽棴瀹冿紝鍚﹀垯浼氭湁鍐呭瓨娉勯湶
聽聽workbook.close();
聽聽return list;
聽}
聽