How do i track clicks with jsp/servlets?

I would like to know how to imitate the click of link in JSP or serlvet, in order to track clicks.
I have pages with links containing tel protocol URIs like this:
Click here to listen!
I want to replace the above with something like this:
Click here to listen!
And have call_tracking.jsp do its tracking stuff and then spawn a phone call, just like the first example does. I do not want to bother the user with another page, hence the need to accomplish the click action programmatically. I presume this feat is achievable via Response header magic, I just don't know the right incantation ;-)
Thanks

You should create a servlet to track the links, let´s say LinkTracker. Here I have an example for you. Each link calls a servlet and pass the url as a parameter.
<html>
  <head>
    <title>Some Links Tracked by the LinkTracker Servlet</title>
  </head>
  <body>
  Some good links for you. Each link is directed
  through the LinkTracker Servlet. Click on a few and visit
  the <a href="LinkTracker">LinkTracker Servlet</a>.
  <ul>
    <li><a href="LinkTracker?link=http://www.google.com">
      Google Site</a></li>
    <li><a href="LinkTracker?link=http://www.yahoo.com">
      Yahoo site</a></li>
    <li><a href="LinkTracker?link=http://java.sun.com">
      Sun Microsystems</a></li>
  </ul>
  </body>
</html>And here the code to LinkTracker servlet
public class LinkTracker extends HttpServlet {
  static private Hashtable links = new Hashtable();
  String tstamp;
  public LinkTracker() {
    tstamp = new Date().toString();
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
    throws IOException, ServletException {
    String link = request.getParameter("link");
    if (link != null && !link.equals("")) {
      synchronized (links){
        Integer count = (Integer) links.get(link);
        if (count == null) {
          links.put(link, new Integer(1));
        else {
          links.put(link, new Integer(1+count.intValue()));
      //here the servlet redirect the client to the link he clicked
      response.sendRedirect(link);
    else {
      response.setContentType("text/html");
      PrintWriter out = response.getWriter();
      request.getSession();
      out.println("<html>");
      out.println("<head>");
      out.println("<title>Links Tracker Servlet</title>");
      out.println("</head>");
      out.println("<body>");
      out.println("<p>Links Tracked Since");
      out.println(tstamp+":</p>");
      if (links.size() != 0) {
        Enumeration enum = links.keys();
        while (enum.hasMoreElements()) {
          String key = (String)enum.nextElement();
          int count = ((Integer)links.get(key)).intValue();
          out.println(key+" : "+count+" visits<br>");
      else {
        out.println("No links have been tracked!<br>");
      out.println("</body>");
      out.println("</html>");
  public void doPost(HttpServletRequest request,
                    HttpServletResponse response)
    throws IOException, ServletException {
    doGet(request, response);
}

Similar Messages

  • How do I double-click with a track-pad?

    I'm new to Mac, and I just bought a beautiful new Apple MacBook laptop. I'm trying to install academic version of Adobe Photoshop 6 (this disk of software was originally made for PCs but I hear it's possible to make it work on a MacBook as well. My question is, how do I double-click with a track-pad, like in order to install new software from actual disks? I'm a multi-media artist and student, among other things. Thanks!
    Apple MacBook   Mac OS X (10.4.4)  

    Hi -
    Double clicking is done by going to System Preferences/Keyboar and Mouse/Trackpad and then selecting the action you'd like.
    However, PS 6 will be more of a task!
    If it's a Windows disc then you'll need to install a Windows XP on your Macbook either through Parallels or Bootcamp.
    Perhaps another 'Mac Friendly' graphics program might be more suiting if you'd like to stick in with the Mac OS X enviornment. Check out these apps....
    http://pure-mac.com/graph.html
    btw, Bootcamp is free!
    Macbook 1.8-)   Mac OS X (10.4.8)   Week 38 base model w/1G Ram

  • How to connect MySql database with JSP

    Dear everyone,
    how to connect MySql database with JSP......

    It's too bad that nobody has ever asked this question before...

  • How to use track effects with new version of GarageBand

    In the version of GarageBand before this one, you could access different effects that you could manage and apply to the different tracks.  Each track had an area containing its set of effects that were either activated or deactivated.  With this removed, i am not sure how to add those same kind of effects.  I am aware of the new nobs that are provided in order to mix and edit trebles, bass, mid, etc., but i want to be able to add different effects such as voice transformer, flanger, chorus, speech enhancer, bit crusher, bass amp, track echo, track reverb, amplifier, etc.  I desperately need help finding out how to do this, as this was a major part of my mixing and producing with GarageBand, and without these given effects, i do not feel as comfortable using GarageBand.

    zachseiden wrote:
    How to use track effects with new version of GarageBand
    this may help:
    http://www.bulletsandbones.com/GB/GBFAQ.html#replacemissingtrackeffectsgbv10
    This FAQ entry offers a Minute GarageBand video tutorial
    (Let the page FULLY load. The link to your answer is at the top of your screen)

  • I lost my iphone4. How can I track it with imei

    I lost my iPhone4 some one stolen it on my phone there is no apps to find it how can I track it  with imei number

    You can't track it via IMEI number, the only way that you could potentially track it is if had Find My iPhone enabled on it (if you did have it enabled then you could try locating it either via http://icloud.com on a computer or Find My iPhone on another device).
    If you haven't already done so then you should report it to the police. You should also contact your carrier and change your iTunes account password, your email account passwords, and any passwords that you'd stored on websites/emails/notes etc.

  • How to implement this function in JSP/Servlet env?

    Hi all,
    I working on a project, it provides functionality to upload file using JSP/Servlet. In the first JSP page, there is file location and submit button. After user select a file to upload and click submit button, a message, like "sending file to XXXX", will be shown on the screen. Once uploading and validation are done on the server-side, a successful/error msg will be shown to user.
    Here I have a question for the "sending..." msg and the successful/error msg. They should be put in one jsp page or in two separate page? how to implement them?
    Thanks for any help!
    Tranquil

    For the sending message... Well, the thing is, when you click submit, it's sending the file to the server and the server is processing it, and this is all done before the "complete" page is sent to the server. So one would need to use some Javascript on the page before the actual submit happens to show some message. This is done on Ebay when you put something for sale, you can upload an image, and there is a little popup message telling you that it's uploading, and it is removed when the process is done. Now, I'm not sure the exact details of how this works, but my educated guess is this:
    1) The onsubmit function of the form checks that the file upload fields have a value (no need to popup a message if no file upload, since that's what usually takes the time, although it could just be assumed there is a file). If a file is to be uploaded, or just want to show the message anyway, a new popup window is opened with the window.open method and the "sending" message is shown (either written via Javascript or just load a small web page to the window).
    2) The popup window, since you can't transfer the window object from the form page to the next page, has to check window.opener for some value that the success/error page would have to set. The success/error page could use it's body onload function to set a variable in it's own window object to denote that the page is loaded. The popup window can use a looping check using setTimeout or setInterval in Javascript to check for window.opener.isLoadedVariable to be present, and if so, close itself.
    I've never done that, but I see no reason why it wouldn't work.

  • Clean URLs with JSP/Servlet

    Hello. I've found some information on how to setup clean URLs for php, but none for JSP/servlet. Hopefully some one can help. Here's what I mean by 'clean URL':
    http://mydomain/employee.jsp?employeeID=1232
    becomes
    http://mydomain/employee/1232
    And, in that second example, the container would dispatch all requests for /employee* to some JSP/servlet. I don't care if the 'clean URL' has to have an extension or not (e.g. mydomain/employee.jsp/1232) although I would prefer to also remove the JSP extension.
    Additionally (if some one has experience with this need): how do I then access the final part of the URL supplied by the client? In other words, how would 1232 be available to the destination JSP/servlet? Does the container convert it into a parameter, i.e.:
    1) client sends request for "mydomain/employee/1232"
    2) container delegates request to "mydomain/employee.jsp?1232"
    Finally (sorry about the length), I don't have access to top-level config files for this site (it's personal use, although I'm pretty familiar with java APIs from my job), so, ideally, I'd like a .htaccess level solution, where the container can just re-route to a JSP.
    If any one has some suggestions, I'd GREATLY appreciate it. Thanks for your time. Take care.

    ...Just occurred to me- this hosting company is NOT using Tomcat. They use resin.
    Thanks.

  • How can I call EJB from JSP/Servlets in iWS?

    Hi!!
    My JSP/Servlets are on iWS, and I deploy EJB on iAS.
    In this case, I don't know how JSP/Servlet call EJb on iAS.
    I'd like to know how I can set JNDI name in JSP/Servlet on iWS.
    I will thank you if you give me a simple example source using JSP/Servlet
    and EJB.
    Thanks in advance!!!
    - Park-

    Park,
    Why Are you running your JSP/Servlets in iWS instead of iAS? For whatever
    reason,
    look at the Converter sample from iAS. You will be doing RMI/IIOP in this
    case and the sample explains in detail what to do.
    hth,
    -robert
    "SungHyun, Park" <[email protected]> wrote in message
    news:9jpfmt$[email protected]..
    Hi!!
    My JSP/Servlets are on iWS, and I deploy EJB on iAS.
    In this case, I don't know how JSP/Servlet call EJb on iAS.
    I'd like to know how I can set JNDI name in JSP/Servlet on iWS.
    I will thank you if you give me a simple example source using JSP/Servlet
    and EJB.
    Thanks in advance!!!
    - Park-

  • How to replace an MDB with a servlet

    I got a situation to replace an MDB with a servlet,How can I do that,more appreciated if u send me some sample code.

    Hi,
    An MDB can be replaced by a normal java class by doing the following.
    Make a jndi lookup for the queue/topic connection factory and then create a javax.jms.QueueConnection. Then create a javax.jms.QueueSession using this connection. Make a JNDI look up for the Queue. Create a javax.jms.QueueReceiver using the created QueueSession. Call start on the QueueConnection and receive a message by calling the receive method on QueueReceiver.
    Thanks,
    marvlex

  • How do i Create charts using JSP/Servlet & Database

    I have to create charts which shows the graph of stock exchange.
    i have a database that keeps the data for creating charts.
    But i did not know how to create charts using jsp-servlet.
    Any Example might help me to go forward.
    Any help will be really appreciated.
    Please Advice me.

    JFreeChart - You can generate the charts then convert them to image formats (PNG and JPEG) all using the JFreeChart API
    http://www.jfree.org/jfreechart/

  • Please help; how to write XML document with JSP?

    I try to write XML document with JSP...
    But I got wrong results everytime.
    The result is not XML file displayed in the browser,
    but HTML file.
    I even tried to use HTML special code for <, >, "
    but still display as HTML file not XML file.
    How to do this?
    Thanks in advance. I put my codes below.
    Sincerely,
    Ted.
    ================
    Here is code for the JSP (called stk.jsp):
    <%@ page contentType="text/xml" %>
    <%@ page import="bean.Stock" %>
    <jsp:useBean id="portfolio" class="bean.Portfolio" />
    <% java.util.Iterator pfolio = portfolio.getPortfolio();
    Stock stock = null; %>
    <?xml version="1.0" encoding="UTF-8"?>
    <portfolio>
    <% while (pfolio.hasNext())
    stock = (Stock) pfolio.next(); %>
    <stock>
    <symbol>
    <%=stock.getSymbol() %>
    </symbol>
    <name><%=stock.getName() %> </name>
    <price><%=stock.getPrice() %> </price>
    </stock>
    <% } %>
    </portfolio>
    =================
    Here is the code for bean.Stock:
    package bean;
    public class Stock implements java.io.Serializable
    String symbol, name;
    float price;
    public Stock(String symbol, String name, float price)
    this.symbol = symbol;
    this.name = name;
    this.price = price;
    public String getSymbol()
    return symbol;
    public String getName()
    return name;
    public float getPrice()
    return price;
    ===============
    And here is bean.Portfolio:
    package bean;
    import java.util.Iterator;
    import java.util.Vector;
    public class Portfolio implements java.io.Serializable
    private Vector portfolio = new Vector();
    public Portfolio()
    portfolio.addElement(new Stock("SUNW", "Sun Microsystem", 34.5f));
    portfolio.addElement(new Stock("HWP", "Hewlett Packard", 15.15f));
    portfolio.addElement(new Stock("AMCC", "Applied Micro Circuit Corp.", 101.35f));
    public Iterator getPortfolio()
    return portfolio.iterator();
    }

    Hi
    I'm not sure whta your query is but I tested your code as it is has been pasted and it seems to work fine. There is an XML output that I'm getting.
    Keep me posted.
    Good Luck!
    Eshwar Rao
    Developer Technical Support
    Sun microsystems
    http://www.sun.com/developers/support

  • Generaating new doc file with jsp servlet.

    Hi friends,
    I developed an application with JSP
    In that i need a data to be fetched nd write in .doc file.
    I mean I want to create new word file nd get my data in that
    like reports generation.
    How can i make this.
    help me pls

    .doc file: I don't think there is any reporting tool that creates .doc. You can create .rtf files with Oracle Reports and many other tools.

  • HOW can I call EJB with JSP?

    Hi, I'm working with JSP and want to include some EJB. I dont know how can I access EJB through JSP. I dont know if I use the right code in JSP for calling EJB. Did someone know how to use that? Can someone tell me if is the right code in JSP in my example?
    Thanks, Kristjan
    THIS IS THE JSP: (useejb.jsp)
    <%@ taglib uri="http://xmlns.oracle.com/j2ee/jsp/tld/ojsp/ejbtaglib.tld" prefix="EJB" %>
    <%@ page import="mypackage1.MySessionEJB" %>
    <%@ page import="mypackage1.MySessionEJBHome" %>
    <%@ page import="mypackage1.impl.MySessionEJBBean" %>
    <HTML>
    <head><TITLE>USEBEAN</TITLE></head>
    <body>
    <EJB:useHome id="mySessionEJBHome" type="mypackage1.MySessionEJBHome" location="java:comp/env/ejb/mySessionEJB" local="false" />
    <EJB:useBean id="mySessionEJBBean" type="mypackage1.impl.MySessionEJBBean" local="false">
    <EJB:createBean instance="<%=mySessionEJBHome.create() %>" />
    </EJB:useBean>
    <%= mySessionEJBBean.calc() %>
    </body>
    </html>
    THIS IS THE EJB CODE:(MySessionEJBBean.java)
    package mypackage1.impl;
    import javax.ejb.SessionBean;
    import javax.ejb.SessionContext;
    import java.lang.String.*;
    public class MySessionEJBBean implements SessionBean
    public void ejbCreate(){}
    public void ejbActivate(){}
    public void ejbPassivate(){}
    public void ejbRemove(){}
    public void setSessionContext(SessionContext ctx){}
    public String calc(String value)
    return value + value;
    public String zanka(String x)
    return x;
    (MySessionEJB.java)
    package mypackage1;
    import javax.ejb.EJBObject;
    import java.rmi.RemoteException;
    public interface MySessionEJB extends EJBObject
    public String calc(String value) throws RemoteException;
    String zanka(String x) throws RemoteException;
    (MySessionEJBHome.java)
    package mypackage1;
    import javax.ejb.EJBHome;
    import java.rmi.RemoteException;
    import javax.ejb.CreateException;
    public interface MySessionEJBHome extends EJBHome
    public MySessionEJB create() throws RemoteException, CreateException;
    }

    You might want to look at using a Java Bean wrapper, this can be done automically using WebSphere. It creates what is called an access bean which the JSP imports.
    HTH,
    J.Clancey

  • Metadata problem with JSP/servlet application

    Hi,
    I developed a JSP/servlet test application that makes
    use of kodo 2.2.3 STANDARD EDITION for its persitence.
    I successfully compile and annotate the application.
    I am also able to successfully generate the db
    schema with schematool.
    Unfortunately, when I run the application using
    Resin 2.0.2, Kodo is unable to initialize properly.
    Initially it was not able to find "system.prefs" file.
    I fixed that by putting "system.prefs" in WEB-INF\classes.
    Unfortunately, Kodo is still unable to initialize and
    gives the following message:
    The system could not initialize; the following registered
    persistent types are missing metadata
    or have not been enhanced:
    [class com.dpov.purchaseorder.PurchaseOrder,
    class com.dpov.catalog.Product,
    class com.dpov.uidgen.counter.Counter,
    class com.dpov.catalog.dao.jdo.CategoryHierarchyEntry,
    class com.dpov.catalog.dao.jdo.CategoryHierarchyDAO,
    class com.dpov.pricelist.PriceInfo,
    class com.dpov.pricelist.PriceList,
    class com.dpov.catalog.Category,
    class com.dpov.lineitem.LineItem,
    class com.dpov.dealer.Dealer,
    class com.dpov.user.User,
    class com.dpov.customer.Customer].
    I use "system.jdo" to describe metadata for the enhancer.
    I tried to put it both in WEB-INF\lib and WEB-INF\classes but
    it still fails.
    Please note that:
    1) my classpath variable is not set
    2) my application's class file are in WEB-INF\classes
    3) kodo jars are in WEB-INF\lib
    4) mysql jdbc driver is in WEB-INF\lib
    5) system.prefs is in WEB-INF\classes
    6) system.jdo is in WEB-INF\classes
    Thanks in advance,
    Andrea
    system.prefs
    <?xml version="1.0"?>
    <prefs>
    <kodo-license-key>VALID KEY!</kodo-license-key>
    <db>
    <username></username>
    <password></password>
    <url>jdbc:mysql://localhost/kodo</url>
    <driver>org.gjt.mm.mysql.Driver</driver>
    <dictionary>
    com.solarmetric.kodo.impl.jdbc.schema.dict.MySQLDictionary
    </dictionary>
    <warn-on-persistent-type-failure>true</warn-on-persistent-type-failure>
    </db>
    <tm-location>java:/TransactionManager</tm-location>
    </prefs>
    system.jdo
    <?xml version="1.0"?>
    <jdo>
    <package name="com.dpov.uidgen.counter">
    <class name="Counter" />
    </package>
    <package name="com.dpov.customer">
    <class name="Customer" />
    </package>
    <package name="com.dpov.user">
    <class name="User" />
    </package>
    <package name="com.dpov.dealer">
    <class name="Dealer" />
    </package>
    <package name="com.dpov.catalog">
    <class name="Product" />
    </package>
    <package name="com.dpov.catalog">
    <class name="Category" />
    </package>
    <package name="com.dpov.catalog.dao.jdo">
    <class name="CategoryHierarchyDAO">
    <field name="categories">
    <collection element-type="com.dpov.catalog.Category"/>
    </field>
    </class>
    </package>
    <package name="com.dpov.catalog.dao.jdo">
    <class name="CategoryHierarchyEntry">
    <field name="attributeValues">
    <map key-type="String" value-type="CategoryHierarchyEntry"/>
    </field>
    <field name="productIds">
    <collection element-type="String"/>
    </field>
    </class>
    </package>
    <package name="com.dpov.lineitem">
    <class name="LineItem" />
    </package>
    <package name="com.dpov.purchaseorder">
    <class name="PurchaseOrder">
    <field name="lineItems">
    <collection element-type="com.dpov.lineitem.LineItem"/>
    </field>
    </class>
    </package>
    <package name="com.dpov.pricelist">
    <class name="PriceInfo" />
    </package>
    <package name="com.dpov.pricelist">
    <class name="PriceList">
    <field name="priceInfos">
    <map key-type="String" value-type="PriceInfo"/>
    </field>
    </class>
    </package>
    </jdo>

    Hi,
    I fixed my problem by setting the system wide variable (WindowsXP)
    CLASSPATH to r:\\dealershop\\WEB-INF\\classes.
    Thanks,
    Andrea
    andrea costantinis wrote:
    Hi,
    I developed a JSP/servlet test application that makes
    use of kodo 2.2.3 STANDARD EDITION for its persitence.
    I successfully compile and annotate the application.
    I am also able to successfully generate the db
    schema with schematool.
    Unfortunately, when I run the application using
    Resin 2.0.2, Kodo is unable to initialize properly.
    Initially it was not able to find \"system.prefs\" file.
    I fixed that by putting \"system.prefs\" in WEB-INF\\classes.
    Unfortunately, Kodo is still unable to initialize and
    gives the following message:
    The system could not initialize; the following registered
    persistent types are missing metadata
    or have not been enhanced:
    [class com.dpov.purchaseorder.PurchaseOrder,
    class com.dpov.catalog.Product,
    class com.dpov.uidgen.counter.Counter,
    class com.dpov.catalog.dao.jdo.CategoryHierarchyEntry,
    class com.dpov.catalog.dao.jdo.CategoryHierarchyDAO,
    class com.dpov.pricelist.PriceInfo,
    class com.dpov.pricelist.PriceList,
    class com.dpov.catalog.Category,
    class com.dpov.lineitem.LineItem,
    class com.dpov.dealer.Dealer,
    class com.dpov.user.User,
    class com.dpov.customer.Customer].
    I use \"system.jdo\" to describe metadata for the enhancer.
    I tried to put it both in WEB-INF\\lib and WEB-INF\\classes but
    it still fails.
    Please note that:
    1) my classpath variable is not set
    2) my application\'s class file are in WEB-INF\\classes
    3) kodo jars are in WEB-INF\\lib
    4) mysql jdbc driver is in WEB-INF\\lib
    5) system.prefs is in WEB-INF\\classes
    6) system.jdo is in WEB-INF\\classes
    Thanks in advance,
    Andrea

  • Using jFreeCharts with JSP-Servlet Web App

    Can someone please help me to get started on using the jFreeCharts in mt JSP Servlet we app? So far I have this in my servlet but I do not know what to do from here.
    protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
    //          create a dataset...
              double[][] data = new double[][] {
              { 1.0, 4.0, 3.0, 5.0, 5.0, 7.0, 7.0, 8.0 },
              { 5.0, 7.0, 6.0, 8.0, 4.0, 4.0, 2.0, 1.0 },
              { 4.0, 3.0, 2.0, 3.0, 6.0, 3.0, 4.0, 3.0 }
              //DefaultCategoryDataset dataset = new DefaultCategoryDataset(data);
              //return DatasetUtilities.createCategoryDataset("Series ", "Factor ", data);
              CategoryDataset dataset = DatasetUtilities.createCategoryDataset("Series ", "Factor ", data);
              JFreeChart chart = ChartFactory.createBarChart(
         "Bar Chart Demo 2", // chart title
         "Category", // domain axis label
         "Score (%)", // range axis label
         dataset, // data
         PlotOrientation.HORIZONTAL, // orientation
         true, // include legend
         true,
         false
         }

    the JFreeChart documentation has examples doing just that.
    And if you don't know how to get a browser to call some resource from some html you should get a beginner's tutorial to html.

Maybe you are looking for

  • What are the exact connections to a BNC2110 to test event counters in MAX?

    I am trying to test my 6034E / BNC-2110 setup, using MAX.  The anallog inputs seem fine, but I am having trouble getting external events counted by Counter 0 or 1.  I am testing the device using Test Panels in MAX.  What is the precise wiring to do t

  • Need to automatically add newly created user account in an existing active directory group.

    Hi All , In my  environment we are having window server 2012 active directory environment.We need to have the newly created active directory user account to get added automatically to the existing active directory group after that new user account cr

  • View Objects and Sequence Numbers

    Hi, I am creating viewobject from query statement. I would like to get nextval from my sequence, there is a bug in jdbc, and it increments by 2, any idea how to correct that and still using data from db ? Jacek

  • Custom Importer Support in AE

    Hi All, I have a quick question. Does Premiere Pro custom importers and synthetic importers are  supported by After Effects CS4? I noticed that imInit, imShutdown and imGetPrefs8 are not invoked by AE. Thanks, Chandan

  • Safari very slow downloading files

    When I bought my MacBook Pro in 2009 I used Safari for few days then I switched to Firefox, and the reason for that is that downloading any kind of files goes very slow to around 5 KB/s while downloading the same file in any other browser is so fast.