java高拍仪前后台处理案例

java 6 2016-02-29 13:03
女装

一.前台页面:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>捷易拍控件测试程序</title>

<script type="text/javascript">
    //启动主
    function Start1_onclick() {
        captrue.bStartPlay();
    }
    //启动副
    function Start2_onclick() {
        captrue.bStopPlay();
        captrue.bStartPlay2(0);
    }
    //停止
    function Stop_onclick() {
        var str = captrue.bStopPlay();
    }
    //保存JPG
    function SaveJPG_onclick() {
        captrue.vSetRotate(0);
        captrue.bSaveJPG("D:\\", "JPG");
    }
    //保存BMP
    function SaveBMP_onclick(){
        captrue.vSetRotate(0);
        captrue.bSaveBMP("D:\\", "BMP");
    }
    //保存PNG
    function SavePNG_onclick(){
        captrue.vSetRotate(0);
        captrue.bSavePNG("D:\\", "PNG");
    }
    //保存TIF
    function SaveTIF_onclick() {
        captrue.vSetRotate(270);
        captrue.vSetDPI(200, 200);
        captrue.vSetTIFPara(0.3, 0.59, 0.11, 0.2);
        var str = captrue.bSaveTIFEx("D:\\", "TIF", 0);
    }
    //保存TifJPG
    function SaveTifJPG_onclick() {
        captrue.vSetRotate(180);
        var str = captrue.bSaveTifJPG("D:\\", "tifJPG");
    }
    //保存灰度图
    function SaveGray_onclick(){
        captrue.vSetRotate(0);
        captrue.bSaveGray("D:\\", "Gray");
    }
    
    function SaveMulTIF_onclick() {
        captrue.vSetRotate(0);
        captrue.vSetDPI(200, 200);
        var str = captrue.bSaveTIFEx("D:\\", "MulTIF", 1);
    }
    //参数设置
    function ParaSet_onclick() {
        captrue.displayVideoPara();
    }
    //PIN设置
    function ParaSetPIN_onclick() {
        captrue.vSetCapturePin();
        captrue.bStartPlay();
    }
    //去黑边
    function CutHB_onclick(el) {
        if(el.checked){
            captrue.vSetDelHBFlag(1);
        } else {
            captrue.vSetDelHBFlag(0);
        }
    }
    //自动矫正
    function Skew_onclick(el) {
        if(el.checked){
            captrue.vSetSkewFlag(1);
        } else {
            captrue.vSetSkewFlag(0);
        }
    }
    //设置分辨率
    function selectResolution(el){
        captrue.vSetResolution(el.value);
    }
    
    //设置图片压缩率
    function setImageQuality(el){
        if(el.value >= 1 && el.value <=100){
            captrue.vSetImageQuality(el.value);
        } else {
            alert("图片压缩率大小必须在1-100之间");
            el.value = 70;
        }
        
    }
    //创建目录
    function CreateDir_onclick(){
        var dir = "d:\\test";
        if(captrue.bCreateDir(dir)){
            alert("创建目录"+dir+"成功");
        }
    }
    
    function DispDir_onclick(){
        captrue.bDispPath("d:\\");
    }
    
    //删除目录
    function DeleteDir_onclick() {
        var dir = "d:\\test";
        if(captrue.bDeleteFile(dir)){
            alert("删除目录"+dir+"成功");
        }
    }
    //删除JPG
    function DeleteJPG_onclick() {
        var file = "D:\\JPG.jpg";
        if(captrue.bDeleteFile(file)){
            alert("删除文件"+file+"成功");
        }
    }
    
    function StartPDF_onclick() {
        var str = captrue.bSavePDFStart("D:\\", "pdffile");
    }
    
    function ColorPDF_onclick() {
        var str = captrue.bSavePDFColorPage();
    }
    
    function BWPDF_onclick() {
        var str = captrue.bSavePDFBWPage();
    }
    
    function EndPDF_onclick() {
        var str = captrue.bSavePDFEnd();
    }
    
    function Base64_onclick() {
        var str = captrue.sGetBase64();
        document.getElementById("S1").value = str;
    }
    
    function upload_onclick(){
        var fileName = "d:\\JPG测试.JPG";
        var re = captrue.bUpLoadImageEx(fileName,"localhost",8080,"/ServletUploadDemo/UploadServlet",true,true);
        alert(re);
    }

</script>
</head>
<body>
    <div style="text-align: center;">
        <object classid="clsid:454C18E2-8B7D-43C6-8C17-B1825B49D7DE"
            id="captrue" width="400" height="300"></object>
    </div>
    <div align="center" style="margin-top: 5px;">
        <input type="button" value="启动主" onclick="Start1_onclick()"/> 
        <input type="button" value="启动副" onclick="Start2_onclick()"/> 
        <input type="button" value="停止" onclick="Stop_onclick()"/>
        <input type="button" value="JPG" onclick="SaveJPG_onclick()"/> 
        <input type="button" value="BMP" onclick="SaveBMP_onclick()"/> 
        <input type="button" value="PNG" onclick="SavePNG_onclick()"/> 
        <input type="button" value="单TIF" onclick="SaveTIF_onclick()"/> 
        <input type="button" value="多TIF" onclick="SaveMulTIF_onclick()"/>
        <input type="button" value="TIFJPG" onclick="SaveTifJPG_onclick()"/>
        <input type="button" value="灰度图" onclick="SaveGray_onclick()"/>
        <input type="button" value="Base64" onclick="Base64_onclick()"/>
        <br/>
        <br/>
        <input type="button" value="参数设置" onclick="ParaSet_onclick()"/>
        <input type="button" value="PIN设置" onclick="ParaSetPIN_onclick()"/>
        <input type="checkbox" id="CutHB" onclick="CutHB_onclick(this)"/><label for="CutHB">设置切黑边</label>
        <input type="checkbox" id="Skew" onclick="Skew_onclick(this)"/><label for="Skew">自动矫正</label>
        <label for="resolutionType">分辨率:</label>
        <select id="resolutionType" onchange="selectResolution(this);">
            <option value="0">设备默认</option>
            <option value="1">320*240</option>
            <option value="2">640*480</option>
            <option value="3">800*600</option>
            <option value="4">1024*768</option>
            <option value="5">1600*1200</option>
            <option value="6">2048*1536</option>
            <option value="7">2592*1944</option>
        </select>
        <label for="imageQuality">图片压缩率(1-100):</label>
        <input type="text" id="imageQuality" size="3" value="70" maxlength="3" onblur="setImageQuality(this)"/>
        <br/>
        <br/>
        <input type="button" value="创建目录" onclick="CreateDir_onclick()"/> 
        <input type="button" value="显示目录" onclick="DispDir_onclick()"/> 
        <input type="button" value="删除目录" onclick="DeleteDir_onclick()"/> 
        <input type="button" value="删除JPG" onclick="DeleteJPG_onclick()"/> 
        <input type="button" value="开始拍PDF" onclick="StartPDF_onclick()"/> 
        <input type="button" value="增加PDF彩页" onclick="ColorPDF_onclick()"/>
        <input type="button" value="增加PDF黑白页" onclick="BWPDF_onclick()"/> 
        <input type="button" value="结束拍PDF" onclick="EndPDF_onclick()"/> 
        <input type="button" value="上传" onclick="upload_onclick()"/> 
    </div>
    <div align="center" style="margin-top: 5px;">
        <textarea rows="7" id="S1" cols="82"></textarea>
    </div>
</body>
</html>

二.后台页面:(注意需要的jar包,commons-fileupload-1.3.jar,commons-io-2.4.jar)

package com.jaeyi;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;



public class UploadServlet extends HttpServlet {
    
    private static final long serialVersionUID = 1L;
    
    private String tempPath = "d:\\upload\\temp";//临时目录
    
    private String path = "d:\\upload";//上传目录
    
    public UploadServlet(){
        super();
    }
    
    public void destroy() {
        super.destroy();
    }
    
    public void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
        this.doGet(request, response);
    }
    
    /**
     * The doGet method of the servlet. <br>
     * 
     * This method is called when a form has its tag value method equals to get.
     * 
     * @param request
     *            the request send by the client to the server
     * @param response
     *            the response send by the server to the client
     * @throws ServletException
     *             if an error occurred
     * @throws IOException
     *             if an error occurred
     */
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setCharacterEncoding("GBK");
        request.setCharacterEncoding("GBK");
        DiskFileItemFactory fac = new DiskFileItemFactory();
        fac.setSizeThreshold(1024);
        fac.setRepository(new File(tempPath));
        ServletFileUpload upload = new ServletFileUpload(fac);
        upload.setFileSizeMax(1024*1024*5);
        try {
            List<FileItem> fileList = upload.parseRequest(request);
            Iterator<FileItem> iter = fileList.iterator();
            while(iter.hasNext()){
                FileItem fileItem = (FileItem)iter.next();
                if(!fileItem.isFormField()){
                    String name = fileItem.getName();
                    String fileSize = new Long(fileItem.getSize()).toString();
                    if(name == null || name.equals("") || fileSize.equals("0"))
                        continue;
                    name = name.substring(name.lastIndexOf("\\")+1);
                    File saveFile = new File(new File(path),name);
                    fileItem.write(saveFile);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new ServletException(e);
        }
    }
    
    public void init() throws ServletException {
        if(!new File(tempPath).exists()){
            new File(tempPath).mkdirs();
        }
        if(!new File(path).exists()){
            new File(path).mkdirs();
        }
    }
}
女装
文章评论