http://www.opencms-forum.de 的一篇 page hit counter

 

RIA知识库 
flex 
RIA 

Jason
Stranger



Joined: Aug 20, 2010
Posts: 5
Status: Offline

Page Hit Count Reply to this Post
Reply with Quote

I have written some JSP code on template JSP to update the page hits count when the page is accessed. The code is ok on offline mode, but when I check it on online mode, the count does not get update. May I know where I should my JSP so that it will be execute everytime?

 

Flo
Advanced Member


Joined: May 7, 2004
Posts: 452
Status: Offline
Re: Page Hit Count Reply to this Post
Reply with Quote

Hi,

what exactky are you doing in your jsp? Are you writing to the VFS? If yes, you have to switch to the Offline project first and publish the modified resource afterwards.

This can be done using methods in CmsRequestContext and CmsPublishManager
----------------------------------------
/**
* Florian Hopf
* Synyx GmbH & Co. KG
*/

 

Jason
Stranger



Joined: Aug 20, 2010
Posts: 5
Status: Offline

Re: Page Hit Count Reply to this Post
Reply with Quote

I use the OAMP Counter Module in my JSP. It will save the count to database. The following is the code snippet:

String uri = cms.getRequest().getParameter("uri") == null ? cms.getRequestContext().getUri() : cms.getRequest().getParameter("uri");

int pageCount = getCounterManager().incrementCounter(uri);

out.println("count = " + pageCount);

On offline mode, everytime I refresh the page, my count increase one. But on online mode, the page count I get remain the same. Seems the page is cached and JSP code snippet does not get executed.

 

Flo
Advanced Member


Joined: May 7, 2004
Posts: 452
Status: Offline
Re: Page Hit Count Reply to this Post
Reply with Quote

Yeah, caching might be the reason. Try to set the cache property for the elements displaying and writing the hit to "never"
----------------------------------------
/**
* Florian Hopf
* Synyx GmbH & Co. KG
*/

 

Jason
Stranger



Joined: Aug 20, 2010
Posts: 5
Status: Offline

Re: Page Hit Count Reply to this Post
Reply with Quote

Yes, it does work if I set cache from "uri;element" to "never".

 

你可能感兴趣的:(thread,jsp,cms,cache,Google)