OAF页面集成条形码或者二维码
OAF页面集成条形码
OAF页面集成二维码跟这个类似,生成二维码需要以下jar包,zxing-core.jar, zxing-javase.jar,可自行去maven下载。
代码如下:
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*; import java.util.HashMap;
import java.util.Map; import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; public class QRCodeServlet extends HttpServlet
{ /**
*
*/
private static final long serialVersionUID = 1L; private String data = "NONE";
private String level = "M";
private int width = 200; public QRCodeServlet()
{
} public void init()
throws ServletException
{
} private void getParameter(HttpServletRequest httpservletrequest)
{
try
{
//httpservletrequest.setCharacterEncoding("iso-8859-1");
String val = httpservletrequest.getParameter("data");
val = new String(val.getBytes("iso-8859-1"), "utf-8");
setParameter("data", val); if(httpservletrequest.getParameter("width") != null)
{
setParameter("width", httpservletrequest.getParameter("width"));
}
if(httpservletrequest.getParameter("level") != null)
{
setParameter("level", httpservletrequest.getParameter("level"));
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
} public void setParameter(String name, String value)
{
if(value != null)
if(name.equals("data"))
data = value;
else
if(name.equals("width"))
width = (new Integer(value)).intValue();
else
if(name.equals("level"))
level = value.toUpperCase();
} public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException
{
getParameter(httpservletrequest); // httpservletrequest.setCharacterEncoding("UTF-8");
// httpservletresponse.setCharacterEncoding("UTF-8");
httpservletresponse.setContentType("image/png");
httpservletresponse.setHeader("Pragma", "no-cache");
httpservletresponse.setHeader("Cache-Control", "no-cache");
httpservletresponse.setDateHeader("Expires", 0L); try {
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>(); if ("L".equals(level)) {
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
}
else if ("M".equals(level)) {
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
}
else if ("Q".equals(level)) {
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q);
}
else if ("H".equals(level)) {
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
}
else {
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q);
} hints.put(EncodeHintType.CHARACTER_SET, "iso-8859-1"); BitMatrix bitMatrix = new MultiFormatWriter().encode(new String(data
.getBytes("GBK"), "iso-8859-1"), BarcodeFormat.QR_CODE, width, width, hints);
MatrixToImageWriter.writeToStream(bitMatrix, "png", httpservletresponse.getOutputStream());
httpservletresponse.getOutputStream().flush();
httpservletresponse.getOutputStream().close(); } catch (WriterException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
} public void doPost(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException
{
try
{
doGet(httpservletrequest, httpservletresponse);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
配置servlet
下载
$ORA_CONFIG_HOME/10.1.3/j2ee/oacore/application-deployments/oacore/html/orion-web.xml
添加如下内容:
<!-- QRCode Servlet --> <servlet>
<servlet-name>QRCode</servlet-name>
<display-name>QRCode</display-name>
<servlet-class>oracle.apps.fnd.test.QRCodeServlet</servlet-class>
</servlet> <!-- QRCodeServlet mapping --> <servlet-mapping>
<servlet-name>QRCode</servlet-name>
<url-pattern>/QRCode</url-pattern>
</servlet-mapping>
调用
http://xxx.xxx.com.cn:8000/OA_HTML/QRCode?data=123567890&width=300&level=H
也可以参考前文中调用条形码的方式将其集成至OAF页面。
附:带logo展示二维码
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException; import javax.imageio.ImageIO;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.swing.ImageIcon; import java.util.HashMap;
import java.util.Map; import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; public class QRCodeServlet extends HttpServlet
{ /**
*
*/
private static final long serialVersionUID = 1L; private String data = "NONE";
private String level = "M";
private int width = 200;
private String charset = "GB2312"; private String logoflag = "N";
private String logopath = "//u02//prod14//appprod14//apps//apps_st//comn//java//classes//oracle//apps//media//logo.png";
private int logowidth = 40; private String removeborder = "N"; public QRCodeServlet()
{
} public void init()
throws ServletException
{
} private void getParameter(HttpServletRequest httpservletrequest)
{
try
{
httpservletrequest.setCharacterEncoding(charset);
String val = httpservletrequest.getParameter("data");
//val = new String(val.getBytes("gb2312"), "UTF-8");
setParameter("data", val); if(httpservletrequest.getParameter("width") != null)
{
setParameter("width", httpservletrequest.getParameter("width"));
}
if(httpservletrequest.getParameter("level") != null)
{
setParameter("level", httpservletrequest.getParameter("level"));
}
if(httpservletrequest.getParameter("logowidth") != null)
{
setParameter("logowidth", httpservletrequest.getParameter("logowidth"));
}
if(httpservletrequest.getParameter("logopath") != null)
{
setParameter("logopath", httpservletrequest.getParameter("logopath"));
}
if(httpservletrequest.getParameter("logoflag") != null)
{
setParameter("logoflag", httpservletrequest.getParameter("logoflag"));
} }
catch(Exception ex)
{
ex.printStackTrace();
}
} public void setParameter(String name, String value)
{
if(value != null)
if(name.equals("data"))
data = value;
else
if(name.equals("width"))
width = (new Integer(value)).intValue();
else
if(name.equals("level"))
level = value.toUpperCase();
else
if(name.equals("logowidth"))
logowidth = (new Integer(value)).intValue();
else
if(name.equals("logopath"))
logopath = value;
else
if(name.equals("logoflag"))
logoflag = value.toUpperCase();
else
if(name.equals("removeborder"))
removeborder = value.toUpperCase();
} public void doGet(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException, IOException
{
getParameter(httpservletrequest); httpservletresponse.setContentType("image/png");
// javax.servlet.ServletOutputStream servletoutputstream = httpservletresponse.getOutputStream();
httpservletresponse.setHeader("Pragma", "no-cache");
httpservletresponse.setHeader("Cache-Control", "no-cache");
httpservletresponse.setDateHeader("Expires", 0L); try {
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>(); if ("L".equals(level)) {
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
}
else if ("M".equals(level)) {
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
}
else if ("Q".equals(level)) {
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q);
}
else if ("H".equals(level)) {
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
}
else {
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
} hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); BitMatrix bitMatrix = new MultiFormatWriter().encode(data, BarcodeFormat.QR_CODE, width, width, hints);
if ("N".equals(logoflag)) // don't display logo
{
MatrixToImageWriter.writeToStream(bitMatrix, "png", httpservletresponse.getOutputStream());
}
else // need display logo
{
ImageIcon icon = new ImageIcon(logopath); BufferedImage barcodeBI = MatrixToImageWriter.toBufferedImage(bitMatrix);
Image scaledImage = barcodeBI.getScaledInstance(256, 256, Image.SCALE_DEFAULT); BufferedImage bimage = new BufferedImage(width, width, BufferedImage.TYPE_INT_RGB);
Graphics2D g = bimage.createGraphics(); g.drawImage(scaledImage, 0, 0, width, width, null);
g.drawImage(icon.getImage(), width/2-logowidth/2, width/2-logowidth/2, logowidth, logowidth, null);
g.dispose(); try {
ImageIO.write(bimage, "png", httpservletresponse.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
finally
{
barcodeBI.flush();
bimage.flush();
}
}
// MatrixToImageWriter.writeToStream(bitMatrix, "png", httpservletresponse.getOutputStream());
httpservletresponse.getOutputStream().flush();
httpservletresponse.getOutputStream().close(); } catch (WriterException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
} public void doPost(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse)
throws ServletException
{
try
{
doGet(httpservletrequest, httpservletresponse);
}
catch(Exception ex)
{
ex.printStackTrace();
}
}
}
OAF页面集成条形码或者二维码的更多相关文章
- C#利用Zxing.net生成条形码和二维码并实现打印的功能
开篇:zxing.net是.net平台下编解条形码和二维码的工具. 下载地址:http://pan.baidu.com/s/1kTr3Vuf Step1:使用VS2010新建一个窗体程序项目: ...
- Android之条形码、二维码扫描框架(非原创)
文章大纲 一.条形码.二维码扫描框架介绍二.条形码.二维码的区别和组成结构介绍三.条形码.二维码扫描框架应用场景四.BGAQRCode-Android框架实战五.项目源码下载六.参考文章 一.条形码. ...
- (整理).net实现条形码与二维码
本文由来源网络的知识点组合而成,感谢分享的作者,文章结尾处给出查询资料连接. 条形码(barcode)是将宽度不等的多个黑条和空白,按照一定的编码规则排列,用以表达一组信息的图形标识符.常见的条形码是 ...
- 实例源码--ZXing识别条形码和二维码识别源码
下载源码 技术要点: 1.ZXing库的 使用 2.识别条形码和二 维码 3.自定义视图 4.源码带有非常详 细的中文注释 ...... 详细介绍: 1.ZXing库 ZXing是个很经典的条码/ ...
- [转]用C#实现的条形码和二维码编码解码器
条形码的标准: 条形码的标准有ENA条形码.UPC条形码.二五条形码.交叉二五条形码.库德巴条形码.三九条形码和128条形码等,而商品上最常使用的就是EAN商品条形码.EAN商品条形码亦称通用商品条形 ...
- 用C#实现的条形码和二维码编码解码器
本文主要介绍可以在C#中使用的1D/2D编码解码器.条形码的应用已经非常普遍,几乎所有超市里面的商品上面都印有条形码:二维码也开始应用到很多场合,如火车票有二维码识别.网易的首页有二维码图标,用户只需 ...
- asp.net 生成、解析条形码和二维码
原文 asp.net 生成.解析条形码和二维码 一.条形码 一维码,俗称条形码,广泛的用于电子工业等行业.比如我们常见的书籍背面就会有条形码,通过扫描枪等设备扫描就可以获得书籍的ISBN(Intern ...
- 基于opencv3.0和下的条形码与二维码识别
其中对条码与二维码的识别分为以下4个步骤 1. 利用opencv和Zbar(或者Zxing)对标准的条形码图片(即没有多余背景干扰,且图片没有倾斜)进行解码,将解码信息显示出来,并与原始信息对比. 2 ...
- C# 利用ZXing.Net来生成条形码和二维码
本文是利用ZXing.Net在WinForm中生成条形码,二维码的小例子,仅供学习分享使用,如有不足之处,还请指正. 什么是ZXing.Net? ZXing是一个开放源码的,用Java实现的多种格式的 ...
随机推荐
- EF 一个实体对象不能由多个 IEntityChangeTracker 实例引用 解决办法
在DAL层中,建立工厂类 namespace DAL { public static class SysDbContextFactory { /// <summary> /// 从Http ...
- centos下gitlab私服完整安装部署(nginx+MySQL+redis+gitlab-ce+gitlab-shell+)
系统环境cat /etc/redhat-release CentOS release 6.8 (Final) nginx -vnginx version: nginx/1.9.15 redis-cli ...
- 查看 nodejs 安装包的相关指令
npm -h 以上指令可以看到npm可用的指令 如果要卸载就用npm uninstall
- 对于“机器视觉(computer version)”的反思
做图像有一段时间了,几个问题进行反思,欢迎讨论 1.机器视觉的本质是什么? 我认为就是通过计算机和数学的方法,对一定形式存储的2d或3d的视觉信号进行增强.延伸,以增加信号的强度: 2.机器视觉的第一 ...
- 2018-2019-1 20189218《Linux内核原理与分析》第七周作业
task_struck数据结构 在Linux内核中,通过task_struct这个结构体对进程进行管理,我们可以叫他PCB或者进程描述符.这个结构体定义在include/linux/sched.h中. ...
- C++ 单例模式(转载)
转载:http://www.cnblogs.com/cxjchen/p/3148582.html 转载:http://blog.csdn.net/hackbuteer1/article/details ...
- 判断某个ImageView的背景图是否是已知的背景图相等
if (ibtn.getDrawable().getConstantState().equals(getResources().getDrawable(R.mipmap.image).getConst ...
- fatal One or more refs for names blocks change upload
前言 今天在提代码时,发现push不到gerrit仓库了,十分的奇怪,和同事沟通后发现,同事可以直接git push origin master而且也可以合并,都是没有问题的,但是就是在gerrit上 ...
- 分析linux内核中的slub内存管理算法
1. 分析的linux内核源码版本为4.18.0 2. 与slub相关的内核配置项为CONFIG_SLUB 3. 一切都从一个结构体数组kmalloc_caches开始,它的原型如下: ] __ro_ ...
- lightoj 1341 Aladdin and the Flying Carpet(算术基本定理)题解
题意:给一个矩形(非正方形)面积a和最小边长b,要求边长均大于b,求这样的矩形有几个 思路:先用到了之前学的质因数分解,还有一个新的公式: 然后我们可以先算出a的所有约数,因为只算约数个数面积重复,所 ...