去下載文件(源代碼和生成好的都要下載)
解壓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>
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26528.html