jsp页面打印条形码

因工作需要,需要jsp页面显示生成条形码.
在网上查了下,找到一开源工具barbecue
从下面的地址下载
http://sourceforge.net/projects/barbecue/
将 barbecue-1.5-beta1.jar 放入工程下的 WEB_INFO\lib目录里
在工程的web.xml里增加 servlet映射文件

<servlet> 
<servlet-name>BarcodeServlet</servlet-name> 
<servlet-class>net.sourceforge.barbecue.BarcodeServlet</servlet-class> 
</servlet> 

<servlet-mapping> 
<servlet-name>BarcodeServlet</servlet-name> 
<url-pattern>/barcode</url-pattern> 
</servlet-mapping> 



jsp页面添加

<img src="<%=request.getContextPath()%>/barcode?data=123456789&type=Code39&width=1&height=20">



参数解释
data=123456789 要生成条形码的字符
type=Code39   表示是code39码 ,条形码类型
width 表示生成的条形码的宽度
height=20 表示生成的条形码的高度

使用稍微需要注意一点的是 条形码下面是否同时显示条形码内容.下面这几句话是设置方法
headless true for headless mode (default value), false to force non-headless mode
drawText (only takes effect if headless = false) true to draw text of barcode, false to omit
"无头" true 为无头模式(默认值为true),false 为强制非无头模式
显示文本(只有headless=false时才有效) 为true 时 显示条形码的内容,false 不显示

简单的说就是默认为条形码下方不显示条形码内容,
如果 headless=false&drawText=true 则条形码下方显示条形码的内容

Just so easy!

官方帮助文档内容如下
Installation:
-------------

Barbecue comes with a pre-compiled war file in the distribution that you can drop straight
into a servlet compatible application server (e.g. Tomcat).

The Barbecue servlet is configured to be available from the following URL by default:

http://host:port/barbecue/

Any requests with this prefix will be routed to the Barbecue servlet.



Usage:
------

The recommended way to use Barbecue as a servlet is to reference it as the src for an
img tag. For example:

<img src="http://localhost:8080/barbecue/barcode?data=123545&height=50"/>



Notes:
------

If you are running the servlet on a headless server (i.e. one with no monitor or graphics
environment) then you must ensure that you use the servlet headless parameter, and also
set the following JVM property:

-Djava.awt.headless=true
-------------------------------------------------------------------


Servlet class: net.sourceforge.barbecue.BarcodeServlet

Required parameters:
--------------------

data the data to encode


Optional parameters:
--------------------

type the barcode type - see below
width the width of the smallest bar in the barcode in pixels
height the height of the barcode in pixels
resolution the output resolution in DPI
checksum true to include a calculated checksum, false to omit (only used by Code39 and derivatives)
headless true for headless mode (default value), false to force non-headless mode
drawText (only takes effect if headless = false) true to draw text of barcode, false to omit


Types:
------

Valid barcode types are (case insensitive):

Code128
Code128A
Code128B
Code128C
EAN128
USPS
ShipmentIdentificationNumber
SSCC18
SCCC14ShippingCode

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值