资源简介
本程序实现了在web页面上,用JAVA的方式,调用扫描仪进行扫描,并上传至远程服务器。并且可以设置扫描范围、扫描精度、以及扫描UI显示等!
代码片段和文件信息
package com.upload;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class AcceptBillsAction extends ActionSupport {
/**
*
*/
private static final long serialVersionUID = 7989035543445860397L;
private String savePath;
private File upload;
private String uploadContentType;
private String uploadFileName;
private String billDirectory;
private String msg;
@SuppressWarnings(“unchecked“)
public String execute() throws Exception {
Map session = ActionContext.getContext().getSession();
session.remove(“operationResult“);
session.remove(“lastupload“);
if (session.get(“login“) == null){
msg = “登录失效!“;
return ActionSupport.SUCCESS;
}
// System.out.println(“-----“);
// Thread.sleep(8000);
// System.out.println(“++++“);
billDirectory = getUploadFileName();
if (billDirectory != null) {
FileOutputStream fos = new FileOutputStream(getSavePath() + “\\“
+ getUploadFileName());
FileInputStream fis = new FileInputStream(getUpload());
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) > 0) {
fos.write(buffer 0 len);
}
fis.close();
fos.close();
} else {
billDirectory = “nophoto.jpg“;
}
billDirectory = savePath + “/“ + billDirectory;
session.put(“lastupload“ billDirectory);
msg = “上传成功!“;
HttpServletResponse response = (HttpServletResponse) ActionContext.getContext().get(ServletActionContext.HTTP_RESPONSE);
response.setContentType(“text/html;charset=GBK“);
write(response msg);
return ActionSupport.SUCCESS;
}
private void write(HttpServletResponse response String message) throws IOException {
response.getWriter().write(message);
response.getWriter().flush();
response.getWriter().close();
}
public String getUploadFileName() {
Date date = new Date();
String str;
try {
str = date.getTime()
+ uploadFileName.substring(uploadFileName.lastIndexOf(“.“));
} catch (Exception e) {
return null;
}
return str;
}
public String getSavePath() {
return ServletActionContext.getServletContext().getRealPath(savePath);
}
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
}
public String getBillDirectory() {
return billDirectory;
}
public void setBillDirectory(String billDirectory) {
this.billDirectory = billDirectory;
}
public void setSavePath(String savePath) {
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 3349 2011-04-12 23:56 javatwain\AcceptBillsAction.java
文件 572064 2010-12-15 11:47 javatwain\iText.jar
文件 229423 2011-10-10 15:06 javatwain\jtwain.dll
文件 38450 2011-10-10 16:16 javatwain\JTwain.jar
文件 1903 2011-10-10 16:19 javatwain\readme.txt
文件 981 2011-10-10 16:19 javatwain\test.html
目录 0 2011-10-10 16:20 javatwain
----------- --------- ---------- ----- ----
846170 7
相关资源
- 基于JSP+Servlet+JavaBean+Dao开发模式——
- javaweb学生信息管理系统112595
- javaWEB面试题大全机会只有一次,千万
- 基于JavaWeb的服装销售管理系统的设计
- 一个纯jsp+Javabean+mysql的学生信息管理
- java web 购物车代码
- 基于WebSocket实现的Android和H5聊天通讯
- 基于javaweb 的bootstrap table 案例源码
- java web接收上传文件服务器端
- Java新闻发布系统源代码
- 自用webstorm配置setting jar包
- weblogic.9.2破解包
- 外文翻译--JSP及其WEB技术
- wqi-3.1.4-palmjoy-cn-0.8 胖鱼汉化版
- javaweb电商项目视频
- 基于javaweb的简单新闻管理系统
- 《Java Web 从入门到精通》 第 2 版 光
- javaweb 增删改查
- 架构探险从零开始写javaweb框架-全部章
- javaWeb 毕业设计 图书管理系统 详细代
- JSP七个小项目代码和笔记汇总(java
- JAVA获取客户端MAC,web获取客户端MAC,
- 大学学籍管理系统 javaweb 课程设计
- javaweb购物车_java 小项目
- GUI版Java五子棋源码,可人机对战,经
- java-web学习demo--最简单的servlet jsp跳转
- 传智播客崔希凡JAVAWEB教程.txt
- websocket-api.jar JAVAjar包
- mongodb+javaSpring实现选课系统demo
- Android之利用WebBrowser实现浏览器
评论
共有 条评论