飛翔的起點

          從這里出發

          導航

          <2008年4月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          統計

          常用鏈接

          留言簿(5)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          教你在java中使用條形碼

           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>

          posted on 2008-04-23 15:20 forgood 閱讀(347) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 怀远县| 恭城| 新昌县| 平谷区| 河曲县| 山丹县| 长葛市| 若羌县| 望江县| 咸阳市| 区。| 浮山县| 怀集县| 璧山县| 鸡泽县| 牡丹江市| 慈溪市| 林甸县| 巴东县| 郓城县| 铜山县| 灵寿县| 高台县| 营山县| 罗山县| 禹城市| 呼伦贝尔市| 信阳市| 凌海市| 会宁县| 吴旗县| 江都市| 台中市| 习水县| 通辽市| 安达市| 宁阳县| 射洪县| 腾冲县| 迭部县| 甘谷县|