Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 847817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:50:53+00:00 2026-05-15T06:50:53+00:00

In the accepted answer in the following question, a SO regular with 13K+ rep

  • 0

In the accepted answer in the following question, a SO regular with 13K+ rep suggests to use a “web bug” (non-cacheable 1×1 img) to be able to track requests in the logs:

Is Google Analytics Accurate?

How can I do this in Java?

Basically, I’ve got two issues:

  • how to make sure the 1×1 image is not cacheable (how to set the header)?

  • how to make sure the query for these 1×1 image will appear in the logs?

I’m looking for exact piece of code because I know how to write a .jsp/servlet and I know how to serve an 1×1 image 🙂

My question is really about the exact .jsp/servlet that I should write and how/what needs to be done so that Tomcat logs the request.

For example I plan to use the following mapping:

<servlet-mapping>
        <servlet-name>WebBugServlet</servlet-name>
        <url-pattern>/webbug*</url-pattern>
</servlet-mapping>

and then use an img tag referencing a “webbug.png” (or .gif), so how do I write the .jsp/servlet?

What/where should I look for in the logs?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T06:50:54+00:00Added an answer on May 15, 2026 at 6:50 am

    The simple method is to add the date timestamp to the image in the JSP. This will prevent the image from getting cached.

    <%
    java.util.Date dt = new java.util.Date ();
    %>
    <img src="/invisible.jpg?<%=dt.getTime ()%>" width="1" height="1">
    

    In your access logs, you can count for your jpg – the output should be

    127.0.0.1 - - [10/Jun/2010:11:38:53 +0530] "GET /mywebapp/jsp/invisible.jpg?1276150133362 HTTP/1.1" 200 991
    127.0.0.1 - - [10/Jun/2010:11:38:54 +0530] "GET /mywebapp/jsp/invisible.jpg?1276150134659 HTTP/1.1" 200 991
    127.0.0.1 - - [10/Jun/2010:11:38:55 +0530] "GET /mywebapp/jsp/invisible.jpg?1276150135627 HTTP/1.1" 200 991
    

    In this approach, you wont need the servlet mapping.

    The alternate approach will involve writing a Filter class to set cache-control headers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Based on the accepted answer to this question I wrote the following code: NSData*
This question is inspired from the accepted answer here . Why does the following
I am following the accepted answer of ASP.NET MVC How to pass JSON object
I am using the accepted answer from this question . The relevant code is
In light of the accepted answer pointing out that returning a non-const reference to
Based the accepted answer to this question I've setup a NetBeans/tomcat environment. In testing
I'm using the accepted answer to this question to help me build an HTML
In another question , the accepted answer suggested replacing a (very cheap) if statement
I was reading over this question and wondered if the accepted answer might also
While I was reading the accepted answer of this question , I had the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.