捷凌网安JAVA频道
捷凌IT教育
首页 资讯动态 认证考试 新手入门 核心技术 高级技术 J2EE J2ME 开源技术 其他技术 论坛
 您现在的位置: 捷凌网安 >> Java >> 核心技术 >> 高级编程 >> 正文
教你条形码barcode4j的使用

作者:佚名 责任编辑:左决 点击数: 更新时间:2008-4-30 2:46:00

   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>
       <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/>
    </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>
       <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/>
    </td>
    <td>
    <h1>datamatrix</h1>
       <img src="<%=request.getContextPath()%>/barcode?msg=20123451&type=datamatrix" height="100px" width=300px/>
    </td>
    </tr>
    </table>

   

  • 上一篇文章:

  • 下一篇文章:
  •  
     最进更新
    普通文章J2SE实现windows读取网卡的物05-11
    普通文章Scala—Java的避难所之main(05-11
    普通文章Spring数据源的灵活配置巧应05-11
    普通文章Spring 与 Log4J 进行动态日05-11
    普通文章Heritrix的多线程ToeThread和05-11
    普通文章应用spring示例开发网站构思05-11
    普通文章Spring 数据源配置与应用05-11
    普通文章Spring中的四种声明式事务的05-11
    普通文章Hibernate+Spring搞定Clob、05-11
    普通文章Hibernate的映射关联关系05-11
     
     推荐文章
    推荐文章Java技术开源搜索引擎04-30
    推荐文章Eclipse中建立自己的JUnit测04-30
    推荐文章Eclipse 3.3上安装jadclipse04-30
    推荐文章spring 编程入门十大问题解答04-30
    推荐文章Java编程中Spring的一些负面04-30
    推荐文章Java应用中Hibernate对多表关04-30
    推荐文章关于hibernate的缓存和CRUD04-30
    推荐文章基于Struts1.2的动态多文件上04-30
    推荐文章演示Struts2实现简单上传代码04-30
    推荐文章J2EE学习笔记--Struts初步认04-30
     
     热点文章
    普通文章J2SE实现windows读取网卡的物05-11
    普通文章Scala—Java的避难所之main(05-11
    普通文章Spring数据源的灵活配置巧应05-11
    普通文章Spring 与 Log4J 进行动态日05-11
    普通文章Heritrix的多线程ToeThread和05-11
    普通文章应用spring示例开发网站构思05-11
    普通文章Spring 数据源配置与应用05-11
    普通文章Spring中的四种声明式事务的05-11
    普通文章Hibernate+Spring搞定Clob、05-11
    普通文章Hibernate的映射关联关系05-11

    | 设为首页 | 加入收藏 | 联系站长 | 广告服务 | 友情链接 | 版权申明 | 网站地图 |

    在线交流 捷凌网安主群:51649627
    Copyright 2007-2008 © 捷凌网安. All rights reserved.
    备案序号:蜀ICP备08001812号