Java 生成条形码
用 JAVA 显示各种规格的条形码(18 种),打印后可以被扫描设备扫描,JAVA 中要生成条
形码码的方法如下:
1. 需要一个 jar 包的支持,这里用的是 barbecue-1.5-beta1.jar;
2. 接下来就可以编写相关程序;
3. Web 中生成条形码程序,在 web.xml 中加入如下 Servlet 配置信息:
<servlet>
<servlet-name>barbecue</servlet-name>
<servlet-class>
net.sourceforge.barbecue.BarcodeServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>barbecue</servlet-name>
<url-pattern>/CreateBarCode</url-pattern>
</servlet-mapping>
4. 编写 JSP 页面
<%@ page contentType="text/html;charset=UTF-8"%>
<%
String code = "135792468";//条形码内容
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script language="javascript">
<!--
NS4 = (document.layers) ? 1 : 0;
visble_property_prefix = (NS4) ? "document.layers." : "";
visble_property_suffix = (NS4) ? ".visibility" : ".style.display";
visble_property_true = (NS4) ? "show" : "block";
visble_property_false = (NS4) ? "hide" : "none";
visble_property_printview = visble_property_prefix + "viewpanel" + visble_property_suffix;
function nowprint() {
window.print();
评论11