Hit counter on JSP page

Hello java-ites,
I want to create a counter on jsp page. How do I do it?
Any help is appreciated.
Many thanks.
-Arun Chellapa.

The way that I have used it as I have a myCounter.txt file that stores the last generated value and is stored.
Make one JSP page with the sample code as
     long counter = 0 ;
     int stringLength = 0;
     String sessionId = null;
     String checkSessionId = null;
     String tempCounter = "";
     boolean flag = false;
     HttpSession hs = request.getSession(true);
     checkSessionId = (String)hs.getValue("sessionId");
     if(checkSessionId == null){
          sessionId = request.getSession().getId();
          hs.putValue("sessionId", sessionId);
          flag = true;
     checkSessionId = (String)hs.getValue("sessionId");
     if(flag) {
          counter = hitCounter.getNextCount();     
     else{
          counter = hitCounter.getCount();
     tempCounter = Long.toString(counter);
     stringLength = tempCounter.length();
     for(int count = 0 ; count < stringLength ; count++){
%>
          <b><%=tempCounter.substring(count, count + 1)%></b>
<%
%>This JSP page can be included in your main JSP page
Here is the Java class
public class HitCounter{
     private long hitCounter;
    public HitCounter(){
          Runtime.getRuntime().addShutdownHook(new SaveCounter(this));
          try{
               DataInputStream dis = new DataInputStream(new FileInputStream(NamedConstants.ERROR_FILE_PATH + "myCounter.txt"));
               hitCounter = dis.readLong();
               dis.close();
          }catch(EOFException ee){
               saveIT();
          }catch(Exception e ){
               System.out.println("Exception thrown " +e);
     public long getNextCount(){
           ++this.hitCounter;
           saveIT();
           return this.hitCounter;
     public long getCount (){
          return this.hitCounter;
     public void saveIT(){
          try{
               DataOutputStream dos = new DataOutputStream(new FileOutputStream(NamedConstants.ERROR_FILE_PATH + "myCounter.txt"));
               dos.writeLong(hitCounter);
               dos.close();
          }catch(Exception e ) {
               System.out.println("Exception thrown while saving "+e);
     protected void finalize(){
          saveIT();
}

Similar Messages

  • Hit counter in jsp

    hi
    i want to know that how can we implement hit counter in our jsp page
    i want 2 hit counter
    1-total number of hits on page
    2-total number of online members at that time
    send me soon

    i have a list of links(which are links to other web applications which i didn't make and can't access) in my jsp retrieved from a table in my database which stores the link name and the number of hits and in their <a href> tag, i redirect them to another jsp, say for example, count.jsp
    in my count.jsp, i get the index of the link i clicked and pass it to my java bean which in turn queries for the url of the link and passes it back to my count.jsp. i laso query for the existing number of hits from the table in the db which is set to 0 by default and also pass it back to my count.jsp
    in my count.jsp, i increment the number of hits by 1 and pass it back to the bean to update the database.
    while this is done, i redirect the count.jsp to the url i retrieved from my bean.
    this could be different if your links are readily accessible and editable by you. you could just add a scriptlet in that link that increments the number of hits in your database.
    i hope you got my point and i hope i helped....

  • Get hit count of a page or a dashboard (usage tracking)

    hi, experts, I found that I can get the query count (using count(*)) from usage tracking.
    but is it possible to get the hit count on a particular tab page or on a particular dashboard? not the query count on a page or a dashboard.
    thank you very much!

    Hi Nicolae,
    I did some digging and I found a few things out.
    Point 1) The OBIEE .dll files are what build up the HTML files based on their code and some "customizable" code in the XML files located in the messages folder of OBIEE (C:\OracleBI\web\msgdb\messages). I say "customizable" with quotes because although these files are editable, it is not supported by Oracle and any upgrade will overwrite your changes. That being said, we cannot change the code in the dll files, so our only other option is to play with the XML files and see if we can inject our script somewhere in their code.
    Point 2) The absolute last message from an XML file is the message that wrote the div with id="idSelsPermissionsDlgDiv". I had to do some grep'ing but I located the file which generated the final DIV. It is the commonuitemplates.xml file line 161. The bad thing is that the particular WebMessage is called multiple times ( I think three times based on my tests) in the building of the HTML. So if you put the code here, it would show up three different times in your HTML. Not ideal :(
    Point 3) The dashboardtemplates.xml document, line 410 is executed about four lines before the final body tag. This WebMessage is only executed once, so it is the closest you can get to the bottom of the page without having a duplicate entry. I recommend you paste the code from google right before the final html tag on line 410.
    Hope this helps!
    -Joe

  • I accidentally moved my hit counter below the page, i cant get it back

    i dragged the hit counter down, and a song down below the page and now i cant scroll down to move it back. I need my hit counter back, and i need my annoying song gone. please help!

    How about making a new text box, filling it with a little typing garbage. Then with this text box selected, move it down and down until your missing items are visible.
    Before deleting them from their current positions, move them up high enough to get above the lowest point on your page before moving this text box down. Once up in the normal page area, then you can delete them and/or move to a normal spot. Once you delete your garbage text box, your footer margins will move back up to their higher location.

  • 2nd Hit Counter on Site not showing up on different page

    I am so close to being done with my Illustration website- 11 pages and only one last bug I can't figure out. I have a second Welcome page that I have hidden and not yet posted. I have no idea where the the hit counter is on the page, it is checked off as there- it doesn't load online or visible on iWeb, yet Insert/button has it as there. I have another hit counter on the site that works fine. I have saved, relaunched, no hit counter on this page. Deleted it, tried again and no luck.
    Here is the site:
    http://web.mac.com/yvette
    The page that I am working on but is not in the menu:
    http://web.mac.com/yvette/iWeb/Site%204/Welcome.html
    The hyperlink works fine but no hit counter.
    Thanks-
    Y

    no hit counter on this page
    The hit counter is in the footer area, but you set the page content height too short, set content height longer or move hit counter out of the footer and into body area.
    One other little issue- On my Menu, the "Fantasy" link doesn't let you use the Fanatsy section at the top of the page. It is one of 11 pages, all connect fine, this one is at the upper most right top
    I think it is block by this image: http://web.mac.com/yvette/iWeb/Site%204/Menufiles/shapeimage9.png
    You need to send it backward.

  • The hit counter button does not show up after publishing page.

    I insert the hit counter button to a new blog post and when I publish, the button does not show up.
    I would really like to use the counter as this is a blog for a class I am teaching, and I would like to track
    student viewing.
    Also, sometimes the colors do not publish properly, specifically with links/rollover feature.
    Help!
    And thanks in advance for all you who know wayyy more than I do!  I hope to return
    the favor someday.

    First, thanks for the quick response Roddy.
    Once I posted the question, similar topics came up and what
    I did was remove the hit counter, publish the page without the hit counter. 
    Then inserted the hit counter again and wah-lah!
    Thanks for your reply, this information is correct and helpful as well.
    Very appreciative!

  • (Hit Counter)Very Urgent Plzzzzzzzzzzzzzzzzzzzz

    Guys can any 1 help me in developing a web page hit counter using JSP based on specific territory .....hope u guys got it ????? For ex: i want to count number of hits only from US
    Message was edited by:
    M......Factor

    Lol, BalusC was written while Java 1.5 wasn't out yet.still no need for the newb-crushing ternary logic :-)
    public class BalusC {
        public boolean readTopic(Topic topic) {
            return !topic.getSubject().toLowerCase().indexOf("urgent") == -1;
    }

  • Hit Counter disappeared. How can I get it back?

    I've read numerous posts re Hit Counter, but none helpful to this:
    I publish only to MobileMe and have had no problem in the past. Problem is: today I removed lots of stuff I had added to my home page during the election campaigns. To remove them, I held down the Command key and dragged through lots of the stuff to select it, then hit Delete. I did not drag through the Hit Counter, nor the Apple logo, yet both of those disappeared too. Looking at the iWeb dropdown menu for adding these items, I saw that there was still a checkmark by the Hit Counter, but not by the Apple logo. So I clicked to check the logo, and it came back on the page no problem.
    But the Hit Counter, already still checked, was nowhere to be found. I increased my footer enormously, and searched in that space... not there. Nowhere.
    Next I unchecked and then rechecked the Hit Counter item in the menu. That didn't do it.
    I hate to uncheck it and then publish, and then check it again and republish. That might work, but I'd lose my count perhaps.
    How can I get back, or simply FIND, the Hit Counter on my page? The check mark says it's there, but I can't find it anywhere, have looked under lots of things on the page... nowhere!
    Thanks, anybody who's got a clue.

    Here's the solution:
    It occurred to me to vastly increase (temporarily) the vertical size of my page. (Remember, doing this with the footer hadn't helped.) When I increased the page size to a whopping 4000, there was the counter AND the original Apple Logo. I moved them into place, then put the vertical page size back to something reasonable. The count was retained.
    Thank you, self! (Sorry this didn't occur to me before posting, but since I have seen nothing of this advice in the discussion already, perhaps this will be helpful to someone else with the same problem.)
    I'll send Apple some feedback and hope they consider adding a line or two to the iWeb Help in it's discussion of the Hit Counter, given that so many of us have encountered problems.

  • Hit counter on .Mac

    I've found that since upgrading to iWeb '08 the hit counter under My Pages on my .Mac home page is no longer there. It worked fine while I was working with iWeb '06. Everything else appears to be in order. The hit counter is working on the web page itself. Anyone with similar experiences?

    I am having a similar issue: hit counter worked for a while but today it no longer appears in published folders/internet. Could there be a corrupt file(i.e .plst)?

  • Hit Counter on iWeb

    Is there any way to track hits on my site without putting that ugly hit counter on my page? - A way that only I can see and no one else?

    There are many ways to hide .mac hit counter, see this thread:
    http://discussions.apple.com/thread.jspa?threadID=1423294&tstart=25
    and here is javascript way, just add the following to your page using HTML Snippet:
    <script type='text/javascript'>
        parent.document.getElementById('CounterDiv').style.visibility = 'hidden';
    </script>

  • Simple tip: fading hit counter

    Although I wanted hit counters on some of my iWeb pages, I didn't want them to be so . . . blah, so bold, so obvious. Two wee little tips:
    1. To have a hit counter on the page but invisible to guests, simply place a shape object on top of it, matched to the color of the background. It'll be there but nobody will be able to see it.
    2. To have your hit counter appear faded or dim, place a shape object on top of it, matched to the color of the background, and set the shape object's translucency to <100% to achieve the desired effect.
    Now nobody can say I never contributed anything to the forum.

    That's a good trick. Thanks for the tip. When you get tired of hiding the Apple counter, you should take a look at Statcounter.com. You can configure this counter to blend in or complement the colors of your page, change the font or the number of digits, and change the size. You can even make the StatCounter counter completely invisible but functional. And you can set it to not count your own visits to your website. Best of all, all of your counters can be tracked easily via a StatCounter Dashboard widget! No more checking the .Mac Homepage just for your hits...just hit F12.

  • .Mac front page hit counts list

    Using iWeb with .Mac, I get hit counts only for the top 5 pages in my .Mac front page status column. I assume that's a standard and have found no settings to permit me to change this.
    Is this it? Can we only monitor the counts for our top 5 pages without having to actually visit (and influence the counts of) the other pages?
    If I'm missing something, I'd be grateful for a friendly hint on how to passively observe the hit totals on all marked pages. If this is just the nature of the beast, chalk it up as another straw in the growing pile under the sign labeled "frustrating shortcomings."

    That's the way it's been since the Homepage days too. I'm not aware of any other way to show the "hits" for more than just the top 5.

  • Web page visit - hit counter

    Please advise of any tutorial or example of a web visit counter. 
    I can create one that increments the count for each visit and refresh but really need something that will count unique visitors.
    Maybe use a session but not sure how to do it.

    Depending on whether this is a casual hit counter, or something more mission-critical, there's a number of ways to accomplish this.
    One option is to increment the counter, then place a cookie on the user's computer. If the cookie is present, don't increment the counter again. Set the cookie to never expire, or expire after a certain window of time (after which the user would be considered "unique" again). Only drawback to this is if the user clears their cookies, then returns, the counter would consider them unique no matter what. Second, you could store each visit as a row in a database, along with the user's IP address and a date/time stamp. Your code could then query that table based on the IP address, and only increment the counter if that IP address is not present. Depending on how long you want to consider a user "unique", you could filter the rows by date. Keep in mind that this could result in a large table, depending on your traffic, so it may be best to have some sort of cut-off time after which you would delete records.
    You could even combine the two methods, if you so desire.
    I'm sure there are many other ways this can be accomplished, but these are two simple means to accomplish your goal.

  • How to find the backend  SQL query of the JSP page in OIC

    Does anybody how the best way to find the backend SQL QUERY of OIV JSP page?

    How To Generate Trace Files in in HTML/JSP (using Profile Option)
    •     • Note: This requires proper responsibility to set SQL Initialization statement using Profile option.      
         Step 1.     Login to the desired Form application.     
         Step 2.     Select +Profile >> System ('Find System Profile Values' screen will pop up)     
         Step 3.     Check 'User' and Type in the Username (in which the account for that user will be trace)     
         Step 4.     Type 'Initialization%' in the Profile box and Hit 'Find' (Click here for preview.)     
         Step 5.     In the User box, type the following statement and Hit 'Save' (Click here for preview)
         BEGIN FND_CTL.FND_SESS_CTL('','','TRUE','TRUE','','ALTER SESSION SET TRACEFILE_IDENTIFIER = TESTING MAX_DUMP_FILE_SIZE = 5000000 EVENTS ='||''''||' 10046 TRACE NAME CONTEXT FOREVER, LEVEL 12'||'''');END;     
         Note:     specify any name you like to identify your trace, in this case, testing is the end name on the trace. You can also specify the amount of data allowable to be in the trace, in this case, 5000000 is the amount set. Make sure you hit 'Save' afterwards.[Quotes in the statement are all 'Single' quotes.]
              specifying TRACEFILE_IDENTIFIER value is mandatory when setting up the trace using the above profile option value
         Step 6.     Login to HTML / JSP page with username/password and start your flow. (Everything you do once login to HTML / JSP will get trace.)     
         Step 7.     Logout of HTML / JSP application once you completed with your flow.      
         Step 8.     Go back to the Profile option in the Form application and delete the Initialization SQL statement, and Hit 'Save'.     
         Step 9.     Log in to the database server or login server and retrieve your trace file.
         Identify and retrieve the trace file using the tracefile_identifier specified in Step 5.
         In this case the tracefile_identifier is “TESTING”. (Click here for Trace file locations) *     
         Note:     If you need to regenerate your trace or tracing a new flow, then repeat Step 1 to Step 8. To avoid self-confusion, choose a different name for your trace identifier everytime you set to trace.     
         Step 10.     See TKPROF section on how to format trace file into readable text.
         Trace Options Definition
         No Trace          Tracing is not activated
         Activities will not get traced.
         Regular Trace
         (Level 1)          Contains SQL, execution statistics, and execution plan.
         Provides execution path, row counts as well as produces smallest flat file.
         Trace with Binds
         (Level 4)          Regular Trace plus value supplied to SQL statement via local variables.
         Trace with Waits
         (Level 8)          Regular Trace plus database operation timings that the SQL waited to have done in order to complete, i.e. disk access.
         Trace with Binds and Waits
         (Level 12)          Regular trace with both waits and binds information.
         Contains the most complete information and will produce the largest trace file.
    ****Send me an email to [email protected],I will share the document with you.

  • Number of component on jsp page

    Hi,
    Is there any limit on number of components(elements) i can have on jsp page.
    when i try to add a component (even object spacer) after a certain number of component, it does not display the page.
    If i want to add more component, how can i add after allowed number of component.

    Hi Saravanan,
    You could use the portal activity report, see http://help.sap.com/saphelp_nw04s/helpdata/en/58/728ea01cf64fff996b827f2a06f9b1/frameset.htm
    Anyhow, if you have developed the iView by yourself, and you are only interested in the hits on that iView, you could implement a counter by yourself, but that should consider cluster environments and how to aggregate the data of these. All this is implemented in the portal activity report, so if that fits somehow, that should be the easiest way for you to go.
    Hope it helps
    Detlev

Maybe you are looking for