发表文章 返回首页
当前位置: bitsCN.com > JAVA > 核心技术 > 高级编程 >

教你条形码barcode4j的使用

时间:2008-04-23 00:00来源:中国网管联盟 作者:bitsCN整理 点击:
1.去http://barcode4j.sourceforge.net/下载文件,(源代码和生成好的都要下载) 2.解压barcode4j-2.0alpha2-bin.zip这个包,在build目录下有barcode4j.jar,在lib目录下有avalon-framework-4.2.0.jar, 将barcode4j.j
  

    1.去http://barcode4j.sourceforge.net/下载文件,(源代码和生成好的都要下载)

中国网管论坛bbs.bitsCN.com

    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了. 54ne.com

    3.解压将barcode4j-2.0alpha2-src.zip,将srcjavaorgkrysalisbarcode4jservlet目录下的BarcodeServlet.java类的代码拷出来,修改默认的图片显示方式,找到        if (format == null) format = MimeTypes.MIME_JPEG;这一行,表示默认的格式为JPEG文件 网管网bitsCN_com

    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> 网管联盟www.bitsCN.com

网管联盟www.bitsCN.com

    5.在页面中添加<img src="<%=request.getContextPath() %>/barcode?msg=12345678" height="50px" width=130px/> 网管网bitsCN_com

    type是生成条形码的类型:

中国网管论坛bbs.bitsCN.com

    看例子就明白了

  <table border="1">
       <tr>
       <td>
       <h1>code39</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=0123456789&type=code39" height="100px" width=300px/>
       </td>
       <td>
       <h1>code128</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=0123456789&type=code128" height="100px" width=300px/>
    </td>
    <td>
       <h1>Codabar</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=0123456789&type=codabar" height="100px" width=300px/> 网管网bitsCN.com
    </td>
    </tr>
    <tr>
    <td>
    <h1>intl2of5</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=01234567890540&type=intl2of5" height="100px" width=300px/>
    </td>
    <td>
    <h1>upc-a</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=012345678912&type=upc-a" height="100px" width=300px/>
    </td>
    <td>
    <h1>ean-13</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=200123457893&type=ean-13" height="100px" width=300px/>
    </td>
    <td>
    <h1>ean-8</h1> 中国网管论坛bbs.bitsCN.com
       <img src="<%=request.getContextPath()%>/barcode?msg=20123451&type=ean-8" height="100px" width=300px/>
    </td>
    </tr>

    <tr>
    <td>
    <h1>postnet</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=01234567890540&type=postnet" height="100px" width=300px/>
    </td>
    <td>
    <h1>royal-mail-cbc</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=012345AS678912&type=royal-mail-cbc" height="100px" width=300px/>
    </td>
    <td>
    <h1>pdf417</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=200123457893&type=pdf417" height="100px" width=300px/>

54com.cn


    </td>
    <td>
    <h1>datamatrix</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=20123451&type=datamatrix" height="100px" width=300px/>
    </td>
    </tr>
    </table> 中国网管联盟www_bitscn_com

54ne.com

    54com.cn

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
最新评论 查看所有评论
发表评论 查看所有评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码:
发布者资料
admin 查看详细资料 发送留言 加为好友 用户等级:注册会员 注册时间:2008-05-08 23:05 最后登录:2009-01-06 00:01
推荐内容