本文介绍了赛峰morpho指纹传感器与Web Java应用程序集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将赛峰(Safran)形态指纹传感器与现有的Java Web应用程序集成在一起.截至目前,我只有safran morpho设备.请指导我启用并与Web应用程序集成.
I have a requirement to integrate Safran morpho finger print sensor with existing java web application . As of now i have only safran morpho device. Please guide me to enable and integrate with web application.
推荐答案
这是您的解决方案.请按照以下步骤操作:
here is your solution.please follow these steps:
- 下载这些文件. https://www.dropbox.com/s/65ztgdzga0l110w/For_Testing. rar?dl = 0
- 安装驱动程序,然后使用MorphoTestPage.html测试您的设备.
- 首先复制html代码.
- 然后使用javascript.
- 然后是servlet.
- download these files. https://www.dropbox.com/s/65ztgdzga0l110w/For_Testing.rar?dl=0
- install drivers and then test your device using MorphoTestPage.html.
- first copy html code.
- then javascript.
- then servlet.
import java.io.FileOutputStream;
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;
import org.apache.tomcat.util.codec.binary.Base64;
public class ThumbUpload extends HttpServlet {
private String filePath;
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
filePath ="your directory path";
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
PrintWriter out = response.getWriter();
String htmlFiles = "";
try {
List<FileItem> items = upload.parseRequest(request);
Iterator<FileItem> iter = items.iterator();
FileItem item = (FileItem) iter.next();
if (item.isFormField())
{
htmlFiles = item.getString();
}
} catch (FileUploadException e) {
System.out.println("Parsing file upload failed."+e);
}
FileOutputStream fos = null;
try {
byte[] contentData = htmlFiles.getBytes();
byte[] decodedData = Base64.decodeBase64(contentData);
String patientId = request.getParameter("patientId");
String imgName = "Thumb_"+patientId+".png";
fos = new FileOutputStream(filePath+imgName);
fos.write(decodedData);
out.println("Uploaded");
} catch (Exception e) {
e.printStackTrace();
} finally {
if (fos != null) {
fos.close();
}
}
}
}
<script>
var template;
function CallFingerAPI()
{
var url = "https://localhost:8080/CallMorphoAPI";
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
fpobject = JSON.parse(xmlhttp.responseText);
console.log(fpobject.Base64BMPIMage);
// Call Servlet
function uploadThumb(image){
var formdata = image;
var fr = new FormData();
fr.append("data", formdata);
var id = "<%=patientId%>";
var url = "ThumbUpload?patientId="+id;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState === 4 && xmlhttp.status === 200){
var response = xmlhttp.responseText;
response = response.replace(/\r?\n|\r/g, "");
response = response.trim();
if(response === "Uploaded"){
alert("Uploaded");
}
else{
alert("Error");
}
}
};
try{
xmlhttp.open("POST",url,true);
xmlhttp.send(fr);
}catch(e){alert("unable to connect to server");
}
}
uploadThumb(fpobject.Base64BMPIMage);
template = fpobject.Base64ISOTemplate;
}
}
var timeout = 5;
xmlhttp.open("POST",url+"?"+timeout,true);
xmlhttp.send();
}
</script>
<script>
<button type="button" class="special button" onclick="CallFingerAPI()">Capture Finger</button>
这篇关于赛峰morpho指纹传感器与Web Java应用程序集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!