电脑故障

位置:IT落伍者 >> 电脑故障 >> 浏览文章

教你条形码barcode4j的使用


发布日期:2023/5/13
 

去下载文件(源代码和生成好的都要下载)

解压barcodejalphabinzip这个包在build目录下有barcodejjar在lib目录下有avalonframeworkjar 将barcodejjar和avalonframeworkjar添加到项目的lib中eclipse中只要复制到webinf下面的lib里面就OK了

解压将barcodejalphasrczip将srcjavaorgkrysalisbarcodejservlet目录下的BarcodeServletjava类的代码拷出来修改默认的图片显示方式找到 if (format == null) format = MimeTypesMIME_JPEG;这一行表示默认的格式为JPEG文件

将以下这段servlet配置在webxml中

<servlet>

<servletname>BarcodeServlet</servletname>

<servletclass>comyournameBarcodeServlet</servletclass>

</servlet>

<servletmapping>

<servletname>BarcodeServlet</servletname>

<urlpattern>/barcode</urlpattern>

</servletmapping>

在页面中添加<img src=<%=requestgetContextPath() %>/barcode?msg= height=px width=px/>

type是生成条形码的类型:

看例子就明白了

<table border=>

<tr>

<td>

<h>code</h>

<img src=<%=requestgetContextPath()%>/barcode?msg=&type=code height=px width=px/>

</td>

<td>

<h>code</h>

<img src=<%=requestgetContextPath()%>/barcode?msg=&type=code height=px width=px/>

</td>

<td>

<h>Codabar</h>

<img src=<%=requestgetContextPath()%>/barcode?msg=&type=codabar height=px width=px/>

</td>

</tr>

<tr>

<td>

<h>intlof</h>

<img src=<%=requestgetContextPath()%>/barcode?msg=&type=intlof height=px width=px/>

</td>

<td>

<h>upca</h>

<img src=<%=requestgetContextPath()%>/barcode?msg=&type=upca height=px width=px/>

</td>

<td>

<h>ean</h>

<img src=<%=requestgetContextPath()%>/barcode?msg=&type=ean height=px width=px/>

</td>

<td>

<h>ean</h>

<img src=<%=requestgetContextPath()%>/barcode?msg=&type=ean height=px width=px/>

</td>

</tr>

<tr>

<td>

<h>postnet</h>

<img src=<%=requestgetContextPath()%>/barcode?msg=&type=postnet height=px width=px/>

</td>

<td>

<h>royalmailcbc</h>

<img src=<%=requestgetContextPath()%>/barcode?msg=AS&type=royalmailcbc height=px width=px/>

</td>

<td>

<h>pdf</h>

<img src=<%=requestgetContextPath()%>/barcode?msg=&type=pdf height=px width=px/>

</td>

<td>

<h>datamatrix</h>

<img src=<%=requestgetContextPath()%>/barcode?msg=&type=datamatrix height=px width=px/>

</td>

</tr>

</table>

上一篇:Map的一种遍历方式

下一篇:介绍——用户认证管理设计方案