欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

flex 手寫在線簽名實現(xiàn)代碼第2/2頁

 更新時間:2009年08月03日 23:40:56   作者:  
企業(yè)信息系統(tǒng)中,有時候需要用到手寫簽名的功能。在這里用flex 實現(xiàn)一個。功能實現(xiàn)了,效果還在改善中。

java端主要有兩個方法。一個是接收客戶端保存圖片時的流,另一個是根據(jù)客戶端的ID返回流。當前例子是運行在google app engine上的。以下是核心代碼:
servlet:
Java代碼
復(fù)制代碼 代碼如下:

/**
*
*/
package com.humanmonth.rea.pic;
import java.io.IOException;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import com.google.appengine.api.datastore.Blob;
import com.humanmonth.framework.web.servlet.Action;
import com.humanmonth.framework.web.servlet.AutoMapperServlet;
import com.humanmonth.framework.web.servlet.ServletUtil;
/**
* @author presses
*
*/
@SuppressWarnings ( "serial" )
public class PictureServlet extends AutoMapperServlet {
private Logger log=Logger.getLogger( this .getClass().getName());
/**
* 測試
*/
@Action ( "sayHi" )
public void sayHi(HttpServletRequest req, HttpServletResponse res) throws IOException {
ServletUtil.outTips(res, "hi" , null );
}
/**
* 保存圖片
*/
@Action ( "savePic" )
public void savePic(HttpServletRequest req, HttpServletResponse res) throws IOException {
String name= ServletUtil
.getStringParameterWithTrim(req, "name" );
if (name== null ){
name="簽名.jpg" ;
}
Picture pic = new Picture(ServletUtil.getStringParameterWithTrim(req, "module" ),name, new Blob(IOUtils.toByteArray(req.getInputStream())));
new PictureService().savePic(pic);
log.info("保存的文件大?。? +pic.getContent().getBytes().length);
ServletUtil.outView(res, pic.getId());
}
/**
* 查找所有圖片
*/
@Action ( "queryAllPic" )
public void queryAllPic(HttpServletRequest req, HttpServletResponse res) throws IOException {
String result = "" ;
for (Picture pic : new PictureService().queryAllPicture()) {
if (pic.getContent() == null ) {
continue ;
}
result += new String(pic.getContent().getBytes(), "utf-8" ) + ":" ;
}
ServletUtil.outView(res, result);
}
/**
* 以ID獲取圖片
*/
@Action ( "queryPicById" )
public void queryPicById(HttpServletRequest req, HttpServletResponse res) throws IOException {
String id = ServletUtil.getStringParameterWithTrim(req, "pid" );
log.info("開始下載文件,ID為:" +id);
Picture pic = new PictureService().queryPicById(Long.valueOf(id));
log.info("下載的文件大?。? +pic.getContent().getBytes().length);
ServletUtil.downloadToClient(res, pic.getContent().getBytes(), pic.getName());
}
}
/**
*
*/
package com.humanmonth.rea.pic;
import java.io.IOException;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import com.google.appengine.api.datastore.Blob;
import com.humanmonth.framework.web.servlet.Action;
import com.humanmonth.framework.web.servlet.AutoMapperServlet;
import com.humanmonth.framework.web.servlet.ServletUtil;
/**
* @author presses
*
*/
@SuppressWarnings("serial")
public class PictureServlet extends AutoMapperServlet {
private Logger log=Logger.getLogger(this.getClass().getName());
    /**
     * 測試
     */
    @Action("sayHi")
    public void sayHi(HttpServletRequest req, HttpServletResponse res) throws IOException {
        ServletUtil.outTips(res, "hi", null);
    }
    /**
     * 保存圖片
     */
    @Action("savePic")
    public void savePic(HttpServletRequest req, HttpServletResponse res) throws IOException {
String name= ServletUtil
.getStringParameterWithTrim(req, "name");
if(name==null){
    name="簽名.jpg";
}
        Picture pic = new Picture(ServletUtil.getStringParameterWithTrim(req, "module"),name, new Blob(IOUtils.toByteArray(req.getInputStream())));
        new PictureService().savePic(pic);
        log.info("保存的文件大?。?+pic.getContent().getBytes().length);
        ServletUtil.outView(res, pic.getId());
    }
    /**
     * 查找所有圖片
     */
    @Action("queryAllPic")
    public void queryAllPic(HttpServletRequest req, HttpServletResponse res) throws IOException {
        String result = "";
        for (Picture pic : new PictureService().queryAllPicture()) {
            if (pic.getContent() == null) {
                continue;
            }
            result += new String(pic.getContent().getBytes(), "utf-8") + ":";
        }
        ServletUtil.outView(res, result);
    }
    /**
     * 以ID獲取圖片
     */
    @Action("queryPicById")
    public void queryPicById(HttpServletRequest req, HttpServletResponse res) throws IOException {
        String id = ServletUtil.getStringParameterWithTrim(req, "pid");
        log.info("開始下載文件,ID為:"+id);
        Picture pic = new PictureService().queryPicById(Long.valueOf(id));
        log.info("下載的文件大?。?+pic.getContent().getBytes().length);
        ServletUtil.downloadToClient(res, pic.getContent().getBytes(), pic.getName());
    }
}

業(yè)務(wù)類:
Java代碼
復(fù)制代碼 代碼如下:

/**
*
*/
package com.humanmonth.rea.pic;
import java.util.List;
import java.util.logging.Logger;
import javax.jdo.PersistenceManager;
import com.humanmonth.framework.dao.JDOTemplate;
/**
* @author presses
*
*/
public class PictureService {
@SuppressWarnings ( "unused" )
private final Logger log=Logger.getLogger( this .getClass().getName());
/**
* 保存圖片
*/
public void savePic( final Picture pic) {
new JDOTemplate<Picture>() {
@Override
public void deal(PersistenceManager pm, List<Picture> result) {
pm.makePersistent(pic);
pm.flush();
}
}.execute();
}
/**
* 以ID和條件獲取圖片
*/
public Picture queryPicById( final Long id) {
return new JDOTemplate<Picture>() {
@Override
public void deal(PersistenceManager pm, List<Picture> result) {
result.add((Picture) pm.getObjectById(Picture.class ,id));
}
}.execute().get(0 );
}
/**
* 查找所有的圖片
*/
public List<Picture> queryAllPicture() {
return new JDOTemplate<Picture>() {
@SuppressWarnings ( "unchecked" )
@Override
public void deal(PersistenceManager pm, List<Picture> result) {
Object obj = pm.newQuery("select from " + Picture. class .getName()).execute();
result.addAll((List<Picture>) obj);
}
}.execute();
}
}
/**
*
*/
package com.humanmonth.rea.pic;
import java.util.List;
import java.util.logging.Logger;
import javax.jdo.PersistenceManager;
import com.humanmonth.framework.dao.JDOTemplate;
/**
* @author presses
*
*/
public class PictureService {
    @SuppressWarnings("unused")
    private final Logger log=Logger.getLogger(this.getClass().getName());
    /**
     * 保存圖片
     */
    public void savePic(final Picture pic) {
        new JDOTemplate<Picture>() {
            @Override
            public void deal(PersistenceManager pm, List<Picture> result) {
                pm.makePersistent(pic);
                pm.flush();
            }
        }.execute();
    }
    /**
     * 以ID和條件獲取圖片
     */
    public Picture queryPicById(final Long id) {
        return new JDOTemplate<Picture>() {
            @Override
            public void deal(PersistenceManager pm, List<Picture> result) {
                result.add((Picture) pm.getObjectById(Picture.class,id));
            }
        }.execute().get(0);
    }
    /**
     * 查找所有的圖片
     */
    public List<Picture> queryAllPicture() {
        return new JDOTemplate<Picture>() {
            @SuppressWarnings("unchecked")
            @Override
            public void deal(PersistenceManager pm, List<Picture> result) {
                Object obj = pm.newQuery("select from " + Picture.class.getName()).execute();
                result.addAll((List<Picture>) obj);
            }
        }.execute();
    }
}

域?qū)ο瘢?
Java代碼
復(fù)制代碼 代碼如下:

package com.humanmonth.rea.pic;
import java.sql.Date;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import com.google.appengine.api.datastore.Blob;
/**
* 圖片
*
* @author presses
*
*/
@PersistenceCapable (identityType = IdentityType.APPLICATION)
public class Picture {
/**
* 主鍵
*/
@PrimaryKey
@Persistent (valueStrategy = IdGeneratorStrategy.IDENTITY)
private Long id;
/**
* 模塊
*/
@Persistent
private String module;
/**
* 文件名
*/
@Persistent
private String name;
/**
* 內(nèi)容
*/
@Persistent
private Blob content;
/**
* 保存時間
*/
@Persistent
private Date date;
public Picture(String module, String name,Blob content) {
this .module = module;
this .name=name;
this .content = content;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this .id = id;
}
public String getModule() {
return module;
}
public void setModule(String module) {
this .module = module;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this .date = date;
}
public Blob getContent() {
return content;
}
public void setContent(Blob content) {
this .content = content;
}
public String getName() {
return name;
}
public void setName(String name) {
this .name = name;
}
}

相關(guān)文章

最新評論