条形码barcode4j的使用
2015-06-09 11:00
323 查看
1.去http://barcode4j.sourceforge.net/下载文件,(源代码和生成好的都要下载)
2.解压barcode4j-2.0alpha2-bin.zip这个包,在build目录下有barcode4j.jar,在lib目录下有avalon-framework-4.2.0.jar, 将barcode4j.jar和avalon-framework-4.2.0.jar添加到项目的lib中,eclipse中只要复制到web-inf下面的lib里面就OK了.
3.解压将barcode4j-2.0alpha2-src.zip,将srcjavaorgkrysalisbarcode4jservlet目录下的BarcodeServlet.java类的代码拷出来,修改默认的图片显示方式,找到 if (format == null) format = MimeTypes.MIME_JPEG;这一行,表示默认的格式为JPEG文件
4.将以下这段servlet配置在web.xml中
<servlet>
<servlet-name>BarcodeServlet</servlet-name>
<servlet-class>com.yourname.BarcodeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BarcodeServlet</servlet-name>
<url-pattern>/barcode</url-pattern>
</servlet-mapping>
5.在页面中添加<img src="<%=request.getContextPath() %>/barcode?msg=12345678" height="50px" width=130px/>
type是生成条形码的类型:
看例子就明白了
<table border="1">
<tr>
<td>
<h1>code39</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=0123456789&type=code39" height="100px" width=300px/>
<td>
<h1>code128</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=0123456789&type=code128" height="100px" width=300px/>
<td>
<h1>Codabar</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=0123456789&type=codabar" height="100px" width=300px/>
<tr>
<td>
<h1>intl2of5</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=01234567890540&type=intl2of5" height="100px" width=300px/>
<td>
<h1>upc-a</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=012345678912&type=upc-a" height="100px" width=300px/>
<td>
<h1>ean-13</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=200123457893&type=ean-13" height="100px" width=300px/>
<td>
<h1>ean-8</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=20123451&type=ean-8" height="100px" width=300px/>
<tr>
<td>
<h1>postnet</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=01234567890540&type=postnet" height="100px" width=300px/>
<td>
<h1>royal-mail-cbc</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=012345AS678912&type=royal-mail-cbc" height="100px" width=300px/>
<td>
<h1>pdf417</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=200123457893&type=pdf417" height="100px" width=300px/>
<td>
<h1>datamatrix</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=20123451&type=datamatrix" height="100px" width=300px/>
2.解压barcode4j-2.0alpha2-bin.zip这个包,在build目录下有barcode4j.jar,在lib目录下有avalon-framework-4.2.0.jar, 将barcode4j.jar和avalon-framework-4.2.0.jar添加到项目的lib中,eclipse中只要复制到web-inf下面的lib里面就OK了.
3.解压将barcode4j-2.0alpha2-src.zip,将srcjavaorgkrysalisbarcode4jservlet目录下的BarcodeServlet.java类的代码拷出来,修改默认的图片显示方式,找到 if (format == null) format = MimeTypes.MIME_JPEG;这一行,表示默认的格式为JPEG文件
4.将以下这段servlet配置在web.xml中
<servlet>
<servlet-name>BarcodeServlet</servlet-name>
<servlet-class>com.yourname.BarcodeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BarcodeServlet</servlet-name>
<url-pattern>/barcode</url-pattern>
</servlet-mapping>
5.在页面中添加<img src="<%=request.getContextPath() %>/barcode?msg=12345678" height="50px" width=130px/>
type是生成条形码的类型:
看例子就明白了
<table border="1">
<tr>
<td>
<h1>code39</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=0123456789&type=code39" height="100px" width=300px/>
<td>
<h1>code128</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=0123456789&type=code128" height="100px" width=300px/>
<td>
<h1>Codabar</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=0123456789&type=codabar" height="100px" width=300px/>
<tr>
<td>
<h1>intl2of5</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=01234567890540&type=intl2of5" height="100px" width=300px/>
<td>
<h1>upc-a</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=012345678912&type=upc-a" height="100px" width=300px/>
<td>
<h1>ean-13</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=200123457893&type=ean-13" height="100px" width=300px/>
<td>
<h1>ean-8</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=20123451&type=ean-8" height="100px" width=300px/>
<tr>
<td>
<h1>postnet</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=01234567890540&type=postnet" height="100px" width=300px/>
<td>
<h1>royal-mail-cbc</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=012345AS678912&type=royal-mail-cbc" height="100px" width=300px/>
<td>
<h1>pdf417</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=200123457893&type=pdf417" height="100px" width=300px/>
<td>
<h1>datamatrix</h1>
<img src="<%=request.getContextPath()%>/barcode?msg=20123451&type=datamatrix" height="100px" width=300px/>
相关文章推荐
- java处理barCode条形码
- 【转】MySQL GRANT REVOKE用法
- Android PopupWindow使用实例
- 解决iframe内弹窗鼠标滚轮事件失效
- NOSQL----memcached(临时键值存储数据库)在centos下的安装与启动
- CocoaPods安装和使用教程 自我实践
- 数据结构基础
- STM32的BootLoader 从SD卡更新固件
- string转datetime
- Android自定义控件——3D画廊和图像矩阵
- C++入门程序作业2
- mongodb执行js脚本(一)---shell执行
- mongodb执行js脚本(一)---shell执行
- Ubuntu 14.04一步一步安装Openstack Kilo版本-1
- 九度OJ-题目1370:数组中出现次数超过一半的数字
- java实现条形码
- nginx将泛解析的匹配域名绑定到子目录配置方法
- Window Pains POJ 2585
- ZBar之ZBarReaderViewController
- 终端控制台笔记