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实现的多种格式的 ...
随机推荐
- c++标准之于gcc/vc/boost等实现相当于jsr规范之于sunjdk/ibmjdk/tomcat/weblogic等实现
春节放假期间,一直在学习c++,越想越发现c++标准之于gcc/vc/boost等实现相当于jsr规范之于sunjdk/ibmjdk/tomcat/weblogic等实现
- c++中对应java ShutdownHook的退出处理器
最近学习cpp(至于为什么,可参考http://www.cnblogs.com/zhjh256/p/6321972.html),c++标准库第二版5.8.2节的时候,发现c++有一个对应java Sh ...
- 基于qml创建最简单的图像处理程序(2)-使用c++&qml进行图像处理
<基于qml创建最简单的图像处理程序>系列课程及配套代码基于qml创建最简单的图像处理程序(1)-基于qml创建界面http://www.cnblogs.com/jsxyhelu/p/8 ...
- 20145313张雪纯Exp8 Web基础
回答问题 (1)什么是表单 表单在网页中主要负责数据采集功能.一个表单有三个基本组成部分: 表单标签:这里面包含了处理表单数据所用CGI程序的URL以及数据提交到服务器的方法. 表单域:包含了文本框. ...
- Android 开发环境配置图文教程(jdk+eclipse+android sdk)
一 相关下载(1) java JDK下载:进入该网页: http://java.sun.com/javase/downloads/index.jsp (或者直接点击下载)如下图: 选择 Downloa ...
- <OFFER03>03_01_DuplicationInArray
#include<cstdio> bool duplicate(int numbers[], int length, int* duplication) { ) return false; ...
- 获取Spring项目配置文件元素
在开发中有时候要获取配置文件里的值,通常可以利用如下方式来读取: public class PropertyUtil { private static Properties p = new Prope ...
- 51NOD 1133 不重叠的线段
1133 不重叠的线段 X轴上有N条线段,每条线段有1个起点S和终点E.最多能够选出多少条互不重叠的线段.(注:起点或终点重叠,不算重叠). 例如:[1 5][2 3][3 6],可以选[2 ...
- 帮助大家理解java中的随机和继承,动态绑定.
package com.ykmimi.javabianchengsixiang; /** * 形状的继承 随机形状生成器 * @author ukyor */ import java.util.Ran ...
- shiro的简单入门使用
这里只是测试登录认证,没有web模块,没有连接数据库,用户密码放在shiro.ini配置中,密码没有加密处理,简单入门. 基于maven 先看目录结构 测试结果 pom.xml <?xml ve ...