/**
 * Excel WorkBook对象类
 * @author zhouqian
 *
 */
public class ExcelWorkBook {
 /** 工作簿 */
 private static HSSFWorkbook workbook = new HSSFWorkbook();
 
 /** 工作表 */
 private HSSFSheet sheet;
 
 /** 表头数据 */
 private String[] tableHeader;
 
 /**
  * 构造函数
  * @param workbookName 工作表名
  * @param tableHeader 表头数据
  */
 public ExcelWorkBook(String workbookName, String[] tableHeader) {
  super();
  this.tableHeader = tableHeader;
  sheet = workbook.createSheet(workbookName);
 }
 
 /**
  * 创建表头
  * @param headerName
  */
 public void createTableHeader(String headerName) {
  HSSFHeader header = sheet.getHeader();
  header.setCenter(headerName);
  HSSFRow headerRow = sheet.createRow(0);
  int cellNumber = tableHeader.length;
  for (int i = 0; i < cellNumber; i++) {
   HSSFCell headerCell = headerRow.createCell((short)i);
   headerCell.setEncoding(HSSFCell.ENCODING_UTF_16);
   headerCell.setCellValue(tableHeader[i]);
  }
 }
 
 /**
  * 创建行
  * @param data 要写入的数据
  * @param rowIndex 第rowIndex行
  */
 public void createTableRow(String[] data, int rowIndex) {
  HSSFRow row = sheet.createRow(rowIndex);
  for (int i = 0; i < data.length; i++) {
   HSSFCell cell = row.createCell((short)i);
   cell.setEncoding(HSSFCell.ENCODING_UTF_16);
   cell.setCellValue(data[i]);
  }
  
 }
 
 /**
  * 创建整个Excel表
  * @param headerName
  */
 public void createExcelSheet(String headerName, String[][] data) {
  this.createTableHeader(headerName);
  
  String[] rowData;
  for (int i = 0; i < data.length; i++) {
   rowData = data[i];
   createTableRow(rowData, i + 1);
  }
  
 }
 
 /**
  * 导出Excel表格
  * @param os
  * @throws IOException
  */
 public void exportExcel(OutputStream os) throws IOException {
  sheet.setGridsPrinted(true);
  HSSFFooter footer = sheet.getFooter();
  footer.setRight("Page " + HSSFFooter.page() + " of " + HSSFFooter.numPages());
  workbook.write(os);
 }

 public HSSFSheet getSheet() {
  return sheet;
 }

 public void setSheet(HSSFSheet sheet) {
  this.sheet = sheet;
 }

 public String[] getTableHeader() {
  return tableHeader;
 }

 public void setTableHeader(String[] tableHeader) {
  this.tableHeader = tableHeader;
 }
}

posted @ 2009-03-10 20:27 chou 阅读(170) | 评论 (0)编辑 收藏
 

/**
 * 邮件客户端
 *
 * @author zhouqian
 *
 */
public class MailClient {
 /** 日志实例 */
 Log logger = LogFactory.getLog(MailClient.class);

 /** 消息对象 */
 private Message message;

 /** 邮件会话 */
 private Session session;

 public MailClient() {
  super();
  this.session = createDefaultSession();
 }

 public MailClient(Session session) {
  super();
  this.session = session;
 }

 public MailClient(Message message) {
  this();
  this.message = message;
 }

 public MailClient(Session session, Message message) {
  super();
  this.session = session;
  this.message = message;
 }

 /**
  * 创建邮件会话
  *
  * @return
  */
 protected Session createDefaultSession() {
  Properties props = new Properties();
  props.put("mail.smtp.host", "smtp.163.com");
  props.put("mail.smtp.auth", "true");
  Session session = Session.getInstance(props);
  session.setDebug(true);
  return session;
 }

 /**
  * 创建纯文本邮件
  *
  * @param recipientTO
  * @param recipientCC
  * @param recipientBCC
  * @return
  * @throws MessagingException
  */
 protected Message createMimeMessage(String subject, String content,
   String recipientTO, String recipientCC, String recipientBCC)
   throws MessagingException {
  Message message = createBlankMessage(recipientTO, recipientCC,
    recipientBCC);

  // 设置邮件标题
  message.setSubject(subject);

  // 设置邮件内容
  message.setText(content);

  // 设置发送时间
  message.setSentDate(new Date(System.currentTimeMillis()));

  // 存储邮件信息
  message.saveChanges();

  return message;
 }

 /**
  * 创建带HTML内容的邮件
  *
  * @param subject
  * @param content
  * @param recipientTO
  * @param recipientCC
  * @param recipientBCC
  * @return
  * @throws MessagingException
  */
 protected Message createHTMLMessage(String subject, String content,
   String recipientTO, String recipientCC, String recipientBCC)
   throws MessagingException {
  Message message = createBlankMessage(recipientTO, recipientCC,
    recipientBCC);

  // 设置邮件标题
  message.setSubject(subject);

  // 设置发送时间
  message.setSentDate(new Date(System.currentTimeMillis()));

  // 创建存放邮件内容的BodyPart对象
  BodyPart bp = new MimeBodyPart();
  bp.setContent(content, "text/html;charset=gb2312");

  // 创建一个MimeMultipart来存放BodyPart对象
  Multipart mp = new MimeMultipart();
  mp.addBodyPart(bp);

  message.setContent(mp);
  message.saveChanges();

  return message;
 }

 /**
  * 创建带附件的邮件
  *
  * @param subject
  * @param content
  * @param recipientTO
  * @param recipientCC
  * @param recipientBCC
  * @return
  * @throws MessagingException
  */
 protected Message createAttachMessage(String subject, String content,
   File attachment, String recipientTO, String recipientCC,
   String recipientBCC) throws MessagingException {
  Message message = createBlankMessage(recipientTO, recipientCC,
    recipientBCC);

  // 设置邮件标题
  message.setSubject(subject);

  // 设置发送时间
  message.setSentDate(new Date(System.currentTimeMillis()));

  // 创建存放邮件内容的BodyPart对象
  BodyPart bp = new MimeBodyPart();
  bp.setContent(content, "text/html;charset=gb2312");

  // 创建一个MimeMultipart来存放BodyPart对象
  Multipart mp = new MimeMultipart();
  mp.addBodyPart(bp);

  // 设置邮件的附件
  bp = new MimeBodyPart();
  FileDataSource fds = new FileDataSource(attachment.getName());
  DataHandler dh = new DataHandler(fds);
  try {
   bp.setFileName(new String(attachment.getName().getBytes("gb2312")));
  } catch (UnsupportedEncodingException e) {
   final String errMess = "Caught exception while encoding file name:"
     + attachment.getName();
   logger.error(errMess);
   throw new MailException(errMess, e);
  }
  bp.setDataHandler(dh);
  mp.addBodyPart(bp);

  message.setContent(mp);
  message.saveChanges();
  return message;
 }

 /**
  * 创建空白邮件
  *
  * @param recipientTO
  * @param recipientCC
  * @param recipientBCC
  * @return
  * @throws MessagingException
  */
 protected Message createBlankMessage(String recipientTO,
   String recipientCC, String recipientBCC) throws MessagingException {
  Message message = new MimeMessage(session);

  // 设置发件人
  InternetAddress from = new InternetAddress("mfktfp2004@163.com");
  message.setFrom(from);

  // 设置收件人
  InternetAddress to = new InternetAddress(recipientTO);
  message.setRecipient(Message.RecipientType.TO, to);
  if (StringUtil.isNotEmpty(recipientCC)) {
   InternetAddress cc = new InternetAddress(recipientCC);
   message.setRecipient(Message.RecipientType.CC, cc);
  }
  if (StringUtil.isNotEmpty(recipientBCC)) {
   InternetAddress bcc = new InternetAddress(recipientBCC);
   message.setRecipient(Message.RecipientType.BCC, bcc);
  }

  return message;
 }

 /**
  * 发送邮件
  *
  * @param message
  * @throws MessagingException
  */
 public void sendEmail(Message message) throws MessagingException {
  // 以smtp方式登陆邮箱
  Transport transport = session.getTransport("smtp");
  transport.connect("smtp.163.com", "mfktfp2004", "19850921"); // SMTP地址,用户名,密码

  // 发送邮件
  transport.sendMessage(message, message.getAllRecipients());
  transport.close();
 }

 /**
  * 发送纯文本邮件
  *
  * @param subject
  * @param content
  * @param recipientTO
  * @param recipientCC
  * @param recipientBCC
  */
 public void sendMimeEmail(String subject, String content,
   String recipientTO, String recipientCC, String recipientBCC) {
  Message message = null;
  try {
   message = createMimeMessage(subject, content, recipientTO,
     recipientCC, recipientBCC);
   sendEmail(message);
  } catch (MessagingException e) {
   logger.error("Send mime email failure", e);
   throw new MailException("Error sending email, failure", e);
  }

 }

 /**
  * 发送带HTML内容的邮件
  *
  * @param subject
  * @param content
  * @param recipientTO
  * @param recipientCC
  * @param recipientBCC
  */
 public void sendHTMLEmail(String subject, String content,
   String recipientTO, String recipientCC, String recipientBCC) {
  Message message = null;
  try {
   message = createHTMLMessage(subject, content, recipientTO,
     recipientCC, recipientBCC);
   sendEmail(message);
  } catch (MessagingException e) {
   logger.error("Send html email failure", e);
   throw new MailException("Error sending email, failure", e);
  }
 }

 /**
  * 发送带附件的邮件
  *
  * @param subject
  * @param content
  * @param recipientTO
  * @param recipientCC
  * @param recipientBCC
  */
 public void sendAttachEmail(String subject, String content,
   File attachment, String recipientTO, String recipientCC,
   String recipientBCC) {
  Message message = null;
  try {
   message = createAttachMessage(subject, content, attachment,
     recipientTO, recipientCC, recipientBCC);
   sendEmail(message);
  } catch (MessagingException e) {
   logger.error("Send html email failure", e);
   throw new MailException("Error sending email, failure", e);
  }
 }

 public Message getMessage() {
  return message;
 }

 public void setMessage(Message message) {
  this.message = message;
 }

 public Session getSession() {
  return session;
 }

 public void setSession(Session session) {
  this.session = session;
 }
 
 public static void main(String[] args) {
  MailClient client = new MailClient();
  client.sendMimeEmail("test", "test", "zhouqian1103@163.com", null, null);
 }
}


public class MailException extends RuntimeException {
 private static final long serialVersionUID = 1L;
 
 /** Throwable实例 */
 protected Throwable throwable;
 
 public MailException() {
  super();
 }
 
 public MailException(String message) {
  super(message);
 }
 
 public MailException(Throwable cause) {
  this.throwable = cause;
 }
 
 public MailException(String message, Throwable cause) {
  super(message);
  this.throwable = cause;
 }
 
 public void printStackTrace(PrintStream ps) {
  super.printStackTrace(ps);
  if (throwable != null) {
   ps.println("with nested Exception:" + throwable);
   throwable.printStackTrace(ps);
  }
 }
 
 public void printStackTrace(PrintWriter pw) {
  super.printStackTrace(pw);
  if (throwable != null) {
   pw.println("with nested Exception:" + throwable);
   throwable.printStackTrace(pw);
  }
 }
 
 public String toString() {
  if (throwable == null) {
   return super.toString();
  } else {
   return super.toString() + "with nested exception:" + throwable;
  }
 }

 public Throwable getThrowable() {
  return throwable;
 }
}


posted @ 2009-03-10 20:26 chou 阅读(250) | 评论 (0)编辑 收藏
 
在测试Hibernate的一对多双向关联映射时,碰到很有趣的问题,跟inverse属性直接相关。

1、People.hbm.xml

<hibernate-mapping default-lazy="false"> 
<class name="com.persistent.People" table="people"> 
<id name="id" column="peopleId" unsaved-value="0"> 
<generator class="increment"> 
</generator> 
</id> 
<property name="name" column="name"></property> 
<set name="addresses" cascade="save-update">
<key column="peopleId" not-null="true" />
<one-to-many class="com.persistent.Address"/>
</set> 
</class>
</hibernate-mapping>

2、Address.hbm.xml

<hibernate-mapping>
<class name="com.persistent.Address" table="address"> 
<id name="id" column="addressId" unsaved-value="0">
<generator class="increment">
</generator>
</id> 
<many-to-one name="people" column="peopleId" insert="false" update="false"></many-to-one> 
<property name="addressName" column="addressName"></property> 
<property name="codeNumber" column="codeNumber"></property> 
</class> 
</hibernate-mapping>
3、People.java和Address.java

public class People ...{ 
private long id; 
private String name; 
private Set addresses = new HashSet(); 
...
}

public class Address ...{ 
private long id; 
private People people; 
private String addressName; 
private String codeNumber; 
...
} 

4、数据库结构

people表:{peopleId,name}

address表:{addressId,peopleId,addressName,codeNumber}

5、测试代码

People people = new People(); 
people.setName("linda"); 
Address address = new Address(); 
address.setAddressName("yunnan"); 
address.setCodeNumber("564123"); 
address.setPeople(people); 
people.getAddresses().add(address); 
Session session = HibernateSessionFactory.getSession(); 
session.beginTransaction(); 
session.save(people); 
session.getTransaction().commit(); 

6、运行结果

  上面测试代码运行起来正确:

Hibernate: select max(peopleId) from people
Hibernate: select max(addressId) from address
Hibernate: insert into people (name, peopleId) values (?, ?)
Hibernate: insert into address (addressName, codeNumber, peopleId, addressId) values (?, ?, ?, ?)
Hibernate: update address set peopleId=? where addressId=?

  如果将People.hbm.xml映射改写一下:

<set name="addresses" cascade="save-update" inverse="true">
<key column="peopleId" not-null="true" />
<one-to-many class="com.persistent.Address"/>
</set>

  不同之处在于添加了inverse="true",结果:

Hibernate: select max(peopleId) from people
Hibernate: select max(addressId) from address
Hibernate: insert into people (name, peopleId) values (?, ?)
Hibernate: insert into address (addressName, codeNumber, addressId) values (?, ?, ?)

  可以看到,peopleId并没有写入到关联的address当中,数据库address表中相应记录的peopleId字段为空。

7、分析

  在Hibernate中,术语inverse是反转的意思,在关联关系中,inverse="false"为主控方,由主控方负责维护对象的关联关系。所以上面的映射文件改动之后,address为主控方,people为被控方,但是测试代码只进行了一个保存操作session.save(people),这是针对people的,因此无法正确级联保存address。而原来的映射文件中(虽然没有明确指明,Hibernate默认inverse="false"),people为主控方,因此保存people时它会保证关联的address的正确保存。

  也就是说,Hibernate仅仅按照主控方对象的状态的变化来同步更新数据库。按照原来的映射文件,people.getAddresses().add(address),即主控方对象的状态发生了改变,因此数据库会跟着对象状态的变化来同步更新数据库;而address.setPeople(people),即被控方对象的状态发生了改变,它是不能触发对象和数据库的同步更新的。
posted @ 2008-09-06 14:41 chou 阅读(149) | 评论 (0)编辑 收藏
 

//保留的位置
var saveLeft,saveTop,saveWidth,saveHeight;
var theBody;
var eventType;    //事件种类, "move"、"resize"
var div;


//创建并设定div的参数
function setDiv(content)
{
 
  //防止重复打开
  if (div)
  {
   eCloseDiv();
  }
  var newLeft,newTop,newWidth,newHeight;
  theBody = document.body;
  
  div = document.createElement("div");
  div.id = "panelDiv";
  div.style.position = "absolute";
  div.style.backgroundColor = "#5F86B5" // 边框颜色
  div.style.padding = "1px 1px 1px 1px";
  div.style.overflow = "hidden";
  div.style.zIndex = 1;
    
  //设定打开的大小和位置
  Function()
  {
   //默认大小默认位置居中打开 
   newWidth = "350px";
   newHeight = "260px";
   newLeft = (theBody.clientWidth - parseInt(newWidth)) / 2 + "px";
   newTop = (theBody.clientHeight - parseInt(newHeight)) / 2 + "px";
   div.style.width = newWidth;
   div.style.height = newHeight;
   div.style.left = newLeft;
   div.style.top = newTop;
  }
  div = setChild(div,content);
  theBody.appendChild(div);
  
//  var ipt = document.getElementsByTagName("input");
//  for(var i = 0; i < ipt.length; i++)
//  {
//   ipt[i].disabled = true;
//  }
}

function setChild(div,content)
{
  //可否移动、调整
  var isMove = true
  var isResize = true;
  
  //底色
  var cDiv = document.createElement;
  var backDiv = cDiv("div");
  backDiv.style.cssText = "left: 0px; top: 0px; width: 100%; height: 100%; background-color:#DFE8F6;" ;
  div.appendChild(backDiv);
  
  //标题
  var topDiv = cDiv("div");
  topDiv.style.cssText = "left: 1px; top: 1px; width: 100%; height: 22px; border-bottom:1px solid #5F86B5; position: absolute; background: url(images/bgd.gif) repeat-x; vertical-align: middle; z-index: 5";
  if (isMove)
  {
   topDiv.style.cursor = "move";
   topDiv.setAttribute("onmousedown", function(){setMove(this)});
  }
  else
  {
   topDiv.style.cursor = "default";
  }
  topDiv.innerHTML = "<span style='top: 5px; left:5px; font-size: 12px; font-weight: bold; color: #102548; position: relative;' onselectstart='return false'>过滤提示</span>";
  div.appendChild(topDiv);
  
  //关闭按钮
  var closeDiv = cDiv("div");
  closeDiv.style.cssText = "right: 8px; top : 4px; width: 16px; height: 16px; position: absolute;  text-align: center; vertical-align: middle; cursor: pointer; z-index:10";
  closeDiv.setAttribute("onclick", function() {eCloseDiv()});
  closeDiv.innerHTML = "<span style='font-size: 12px; font-weight: bold; color: #0E377A;' title='Esc快捷键'><img src = 'images/close.gif'/></span>";
  div.appendChild(closeDiv);
  
  //内容
  var contentDiv = cDiv("div");
  contentDiv.style.cssText = "left: 1px; top: 35px; background-color:#DFE8F6; width: 100%; position: absolute; overflow: auto;  padding:5px;";
  contentDiv.style.height = (parseInt(div.style.height) - 40) + "px";
  contentDiv.innerHTML = "<table style='width: 100%; height: 100%; text-align: left; vertical-align: hidden'><tr><td><p>"+content+"</p></td></tr></table>";
  div.appendChild(contentDiv);
  
  //调整大小
  var reDiv = cDiv("div");
  reDiv.style.cssText = "right: 0px; bottom: 0px; width: 5px; height: 5px; position: absolute;";
  if (isResize)
  {
   reDiv.style.cursor = "se-resize";
   reDiv.setAttribute("onmousedown", function(){setResize(this)});
  }
  else
  {
   reDiv.style.cursor = "default";
  }
  div.appendChild(reDiv);
  
  return div;
}

var oX, oY, oLeft, oTop, oWidth, oHeight; //存储原始移动前的位置
var divClone, oDiv;   //克隆的节点和原始节点
var oTime;
//clone拖移的节点
function setMove(obj)
{
  if (event.button == 1)
  {
   if (oTime)
   {
    clearTimeout(oTime);
    divClone.parentNode.removeChild(divClone);
   }
   oDiv = obj.parentNode;
   divClone = oDiv.cloneNode(true);
   divClone.style.filter = "Alpha(opacity=50)";
   divClone.childNodes[1].setAttribute("onmousemove", function(){startMove(this)});
   divClone.childNodes[1].setAttribute("onmouseup", function(){endMove()});
   oX = parseInt(event.clientX);
   oY = parseInt(event.clientY);
   oLeft = parseInt(divClone.style.left);
   oTop = parseInt(divClone.style.top);
   document.body.appendChild(divClone);
   divClone.childNodes[1].setCapture();
   eventType = "move";
  }
}

//拖移
function startMove(obj)
{
  if (eventType == "move" && event.button == 1)
  {
   var moveDiv = obj.parentNode;
   moveDiv.style.left = (oLeft + event.clientX - oX) + "px";
   moveDiv.style.top = (oTop + event.clientY - oY) + "px";
  }
}

//拖移结束调用动画
function endMove()
{
  if (eventType == "move")
  {
   divClone.childNodes[1].releaseCapture();
            move(parseInt(divClone.style.left), parseInt(divClone.style.top));
   eventType = "";
  }
}

//移动的动画
function move(aimLeft, aimTop)
{
  var nowLeft = parseInt(oDiv.style.left);
  var nowTop = parseInt(oDiv.style.top);
  var moveSize = 30;
  if (nowLeft > aimLeft + moveSize || nowLeft < aimLeft - moveSize || nowTop > aimTop + moveSize || nowTop < aimTop - moveSize)
  {
   oDiv.style.left = aimLeft > nowLeft + moveSize ? (nowLeft + moveSize) + "px" : aimLeft < nowLeft - moveSize ? (nowLeft - moveSize) + "px" : nowLeft + "px";
   oDiv.style.top = aimTop > nowTop + moveSize ? (nowTop + moveSize) + "px" : aimTop < nowTop - moveSize ? (nowTop - moveSize) + "px" : nowTop + "px";
   oTime = setTimeout("move(" + aimLeft + ", " + aimTop + ")", 1);
  }
  else
  {
   oDiv.style.left = divClone.style.left;
   oDiv.style.top = divClone.style.top;
   divClone.parentNode.removeChild(divClone);
   divClone == null;
  }
}

//clone调整大小的节点
function setResize(obj)
{
  if (event.button == 1)
  {
   if (oTime)
   {
    clearTimeout(oTime);
    divClone.parentNode.removeChild(divClone);
   }
   oDiv = obj.parentNode;
   divClone = oDiv.cloneNode(true);
   divClone.style.filter = "Alpha(opacity=50)";
   divClone.childNodes[4].setAttribute("onmousemove", function(){startResize(this)});
   divClone.childNodes[4].setAttribute("onmouseup", function(){endResize()});
   oX = parseInt(event.clientX);
   oY = parseInt(event.clientY);
   oWidth = parseInt(divClone.style.width);
   oHeight = parseInt(divClone.style.height);
   document.body.appendChild(divClone);
   divClone.childNodes[4].setCapture();
   eventType = "resize";
  }
}

//拖动调整大小
function startResize(obj)
{
  if (eventType == "resize" && event.button == 1)
  {
   var nX = event.clientX;
   var nY = event.clientY;
   if (nX > oX - oWidth && nY > oY - oHeight + 40)
   {
    var resizeDiv = obj.parentNode;
    resizeDiv.style.width = (oWidth + event.clientX - oX) + "px";
    resizeDiv.style.height = (oHeight + event.clientY - oY) + "px";
    resizeDiv.childNodes[3].style.height = (parseInt(resizeDiv.style.height) - 40) + "px";
   }
  }
}

//调整大小结束
function endResize()
{
  if (eventType == "resize")
  {
   divClone.childNodes[4].releaseCapture();
            resize(parseInt(divClone.style.width), parseInt(divClone.style.height));
   eventType = "";
  }
}

//调整大小的动画
function resize(aimWidth, aimHeight)
{
  var nowWidth = parseInt(oDiv.style.width);
  var nowHeight = parseInt(oDiv.style.height);
  var resizeSize = 30;
  if (nowWidth > aimWidth + resizeSize || nowWidth < aimWidth - resizeSize || nowHeight > aimHeight + resizeSize || nowHeight < aimHeight - resizeSize)
  {
   oDiv.style.width = aimWidth > nowWidth + resizeSize ? (nowWidth + resizeSize) + "px" : aimWidth < nowWidth - resizeSize ? (nowWidth - resizeSize) + "px" : nowWidth + "px";
   oDiv.style.height = aimHeight > nowHeight + resizeSize ? (nowHeight + resizeSize) + "px" : aimHeight < nowHeight - resizeSize ? (nowHeight - resizeSize) + "px" : nowHeight + "px";
   oDiv.childNodes[3].style.height = (parseInt(oDiv.style.height) - 40) + "px";
   oTime = setTimeout("resize(" + aimWidth + ", " + aimHeight + ")", 1);
  }
  else
  {
   oDiv.style.width = divClone.style.width;
   oDiv.style.height = divClone.style.height;
   oDiv.childNodes[3].style.height = (parseInt(oDiv.style.height) - 40) + "px";
   divClone.parentNode.removeChild(divClone);
   divClone == null;
  }
}

//关闭DIV
function eCloseDiv()
{  
 
  if (div)
  {
   div.parentNode.removeChild(div);
//   var ipt = document.getElementsByTagName("input");
//   for(var i = 0; i < ipt.length; i++)
//   {
//    ipt[i].disabled = false;
//   }
   div = null;
  }
}

//保留位置和大小
function saveDiv()
{
  if (div)
  {
   saveLeft = div.style.left;
   saveTop = div.style.top;
   saveWidth = div.style.width;
   saveHeight = div.style.height;
  }
}

//快捷键
document.onkeydown = function()
{
  event.keyCode == 27 ? eCloseDiv() : null;  //Esc快捷键
  event.ctrlKey && (event.keyCode == 83 || event.keyCode == 115) ? saveDiv() : null; //ctrl+s保存位置
  event.ctrlKey && event.keyCode == 13 ? setDiv() : null //ctrl+enter打开Div
  !event.ctrlKey && (event.keyCode == 37 || event.keyCode == 38 || event.keyCode == 39 || event.keyCode == 40) ? arrowMove(event.keyCode) : null;
  event.ctrlKey && (event.keyCode == 37  || event.keyCode == 38 || event.keyCode == 39 || event.keyCode == 40) ? arrowResize(event.keyCode) : null;
}

// 单击层以外的地方隐藏层
document.onclick = function()
{
  if (div)
  {
      if(typeof event.srcElement.message == "undefined")
   {
     if (div.componentFromPoint(event.clientX,event.clientY)=="outside")
     {
     eCloseDiv();
      
     }
   }
  }
}

//上下左右箭头移动div
function arrowMove(eKeyCode)
{
  if (div)
  {
   var isMove = document.getElementById("isMove").checked;
   if (isMove)
   {
    switch(eKeyCode)
    {
     case 37:
      div.style.left = (parseInt(div.style.left) - 1) + "px"; //left
      break
     case 38:
      div.style.top = (parseInt(div.style.top) - 1) + "px"; //up
      break
     case 39:
      div.style.left = (parseInt(div.style.left) + 1) + "px"; //right
      break
     case 40:
      div.style.top = (parseInt(div.style.top) + 1) + "px"; //down
      break
    }
   }
  }
}

//ctrl+上下左右箭头调整div大小
function arrowResize(eKeyCode)
{
  if (div)
  {
   var isResize = document.getElementById("isResize").checked;
   if (isResize)
   {
    switch(eKeyCode)
    {
     case 37:
      div.style.width = (parseInt(div.style.width) - 1) + "px"; //left
      break
     case 38:
      div.style.height = (parseInt(div.style.height) - 1) + "px"; //up
      break
     case 39:
      div.style.width = (parseInt(div.style.width) + 1) + "px"; //right
      break
     case 40:
      div.style.height = (parseInt(div.style.height) + 1) + "px"; //down
      break
    }
   }
  }
}

posted @ 2008-08-28 12:42 chou 阅读(302) | 评论 (0)编辑 收藏
 

前台:
     var url = "filter.do?action=filter";
     var xmlDocument = XmlDocument.create();
     var filterInfo = xmlDocument.createElement("filterInfo");
     xmlDocument.appendChild(filterInfo);
     appendSimpleChildNode(xmlDocument, filterInfo, "type", type);
     appendSimpleChildNode(xmlDocument, filterInfo, "condition", condition);  
     xmlHttp = XmlHttp.create();
     xmlHttp.open("POST", url, false);
     xmlHttp.send(xmlDocument.xml);
     var xmlString = xmlHttp.responseText;
     return xmlString;

后台:

        SAXBuilder saxb = new SAXBuilder();
        Document doc = saxb.build(request.getInputStream());
        Element root = doc.getRootElement();
        String type = root.getChildText("type");
        String inputCondition = root.getChildText("condition");
       

posted @ 2008-08-28 12:37 chou 阅读(218) | 评论 (1)编辑 收藏
仅列出标题
共2页: 1 2 下一页