Location header servlet 1.1

    It is a Java servlet lets you execute HTTP HEAD requests against an arbitrary URL and return location header in JSON (JSONP) format. So your JavaScript application will be able to check the real URL in case of redirection.

The idea is very simple. Servlets returns JavaScript code. So adding this JavaScript code dynamically to your page lets you bypass any sandbox restrictions and deal with the remote data sources.

How to use it:

a) copy locationPackage.jar into your WEB-INF/lib directory.

b) define a servlet in your web.xml file.


define a mapping:


Servlet accepts the following parameters:

url - URL to be requested
callback - optional. Describes a name for your JavaScript callback
agent - optional. Describes User-Agent header

    The following example illustrates the usage. This code requests the real URL from tinyurl service. JavaScript function f describes our callback.

<script language="JavaScript">

function f(info)
  var s="Response:" + info.responseCode+"\n"
   +"Location:" + info.location;


var e = document.createElement("script");
e.src = 'http://your_server/servlet/Location?url=http://tinyurl.com/67ymge7&callback=f';


    For downloading:  locationPackage.jar   

  © Coldbeans     Comments?

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

Also in JSOS: