QR code servlet ver. 1.3


This servlet lets you produce QR codes for text. QR codes are a type of two-dimensional barcode. They are also known as hardlinks or physical world hyperlinks. QR Codes store up to 4,296 alphanumeric characters of arbitrary text. This text can be anything, for example URL, contact information, a telephone number etc. Internally servlet uses Google Charts API and caches data for the better performance.

How to use this servlet:

a) download qrcodePackage.jar and save it in WEB-INF/lib

b) describe this servlet in web.xml file. Servlet accepts the following initial parameters:
dir - Describes an existing directory on your server for the saved content
proxyHost - Optional parameter. Describes a proxy host for your internet connection
proxyPort - Optional parameter. Describes a proxy port for your internet connection
width - Optional parameter. Describes a width for the image. Default value is 300
height - Optional parameter. Describes a height for the image. Default value is 300
choe - Optional parameter. Describes an encoding -how to encode the data in the chart. Here are the available values: UTF-8 (default), Shift_JIS, ISO-8859-1
chld - Optional parameter. Describes error correction level and margin (see QR chart for details)

For example:
 


<servlet>
  <servlet-name>QRCodeServlet</servlet-name>
  <servlet-class>com.jsos.qr.QRCodeServlet</servlet-class>
  <init-param>
   <param-name>dir</param-name>
   <param-value>/my_cache</param-value>
  </init-param>
</servlet>

c) describe a mapping for this servlet in web.xml file. E.g.:
 


<servlet-mapping>
  <servlet-name>QRCodeServlet</servlet-name>
  <url-pattern>/servlet/qrcode</url-pattern>
</servlet-mapping>

and now in your applications you can use servlet in the following forms
 


/servlet/qrcode?your_url

or
 


/servlet/qrcode?your_encoded_data

e.g. <img src="/servlet/qrcode?http://www.servletsuite.com"/>

and you will get the following image:

http://www.servletsuite.com

One interesting feature - you can use this servlet without parameters. In this case it will create QR-code for URL from referrer header. This option lets you simply add servlet's image to any page get it's QR-code:

<img src="/servlet/qrcode"/>

You can describe also the proxy settings for the servlet itself. Parameters are proxyHost and proxyPort. E.g.:
 


<servlet>
  <servlet-name>QRCodeServlet</servlet-name>
  <servlet-class>com.jsos.qr.QRCodeServlet</servlet-class>
  <init-param>
   <param-name>dir</param-name>
   <param-value>/my_cache</param-value>
  </init-param>

  <init-param>
   <param-name>proxyHost</param-name>
   <param-value>192.168.0.1</param-value>
  </init-param>

  <init-param>
   <param-name>proxyPort</param-name>
   <param-value>8080</param-value>
  </init-param>
</servlet>

   For downloading:

    QR code servlet:  qrcodePackage.jar
 

 ©  Coldbeans     Comments?

See also JSOS - the largest collection of servlets and filters.

Also in JSOS: