關於SSH中對於action的監聽問題(關於系統計數)
最近想做一個系統計數功能,網上看了一下資料,用的是session監聽,每當一個session建立或失效,count自動增減1,監聽類如下
public class CounterAction extends DispatchAction implements HttpSessionListener {
private static int activeSessions = 0;
private CounterService counterService;
public CounterService getCounterService()
{
return counterService;
}
public void setCounterService(CounterService counterService)
{
this.counterService = counterService;
}
public ActionForward updatepv(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
counterService = new CounterServiceImpl();
Integer time = new Integer(Integer.parseInt("20090403"));
Counter counter = this.counterService.findCounterByTime(time);
this.counterService.updateCounterPv(counter, activeSessions);
request.getSession(true).setAttribute("counter", counter);
return null;
}
public ActionForward showpv(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Integer time = new Integer(20090403);
Counter counter = this.counterService.findCounterByTime(time);
this.counterService.updateCounterPv(counter, activeSessions);
return mapping.findForward("success");
}
public void sessionCreated(HttpSessionEvent se) {
activeSessions++;
Integer time = new Integer(20090403);
String[] locations = {"applicationContext-common.xml","applicationContext-counter.xml"};
ApplicationContext ctx = new ClassPathXmlApplicationContext(locations);
CounterDAO counterdao = (CounterDAOImpl) ctx.getBean("counterDAO");
List list=(List<Counter>) counterdao.findCounterByTime(time);
Counter counter = (Counter) list.get(0);
Iterator counterIterator = list.iterator();
while(counterIterator.hasNext()){
counter = (Counter)counterIterator.next();
}
counter.setPv(activeSessions);
counterdao.updateCounter(counter);
}
public void sessionDestroyed(HttpSessionEvent se) {
if(activeSessions > 0)
activeSessions--;
}
public static int getActiveSessions() {
return activeSessions;
}
}
這個類執行也不報錯,資料庫操作也能透過,問題是似乎資料庫並不commit,我在資料庫中用的是spring getHibernate()的相關方法,我還特意做了一個action,如果人為的去觸發這個action,資料庫一切按照原計劃正常執行(可以更新,查詢),也就是說這個類應該沒錯,可是一旦用了監聽session後,就不更新資料庫,也不報錯,各位大俠幫忙看看
public class CounterAction extends DispatchAction implements HttpSessionListener {
private static int activeSessions = 0;
private CounterService counterService;
public CounterService getCounterService()
{
return counterService;
}
public void setCounterService(CounterService counterService)
{
this.counterService = counterService;
}
public ActionForward updatepv(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
counterService = new CounterServiceImpl();
Integer time = new Integer(Integer.parseInt("20090403"));
Counter counter = this.counterService.findCounterByTime(time);
this.counterService.updateCounterPv(counter, activeSessions);
request.getSession(true).setAttribute("counter", counter);
return null;
}
public ActionForward showpv(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
Integer time = new Integer(20090403);
Counter counter = this.counterService.findCounterByTime(time);
this.counterService.updateCounterPv(counter, activeSessions);
return mapping.findForward("success");
}
public void sessionCreated(HttpSessionEvent se) {
activeSessions++;
Integer time = new Integer(20090403);
String[] locations = {"applicationContext-common.xml","applicationContext-counter.xml"};
ApplicationContext ctx = new ClassPathXmlApplicationContext(locations);
CounterDAO counterdao = (CounterDAOImpl) ctx.getBean("counterDAO");
List list=(List<Counter>) counterdao.findCounterByTime(time);
Counter counter = (Counter) list.get(0);
Iterator counterIterator = list.iterator();
while(counterIterator.hasNext()){
counter = (Counter)counterIterator.next();
}
counter.setPv(activeSessions);
counterdao.updateCounter(counter);
}
public void sessionDestroyed(HttpSessionEvent se) {
if(activeSessions > 0)
activeSessions--;
}
public static int getActiveSessions() {
return activeSessions;
}
}
這個類執行也不報錯,資料庫操作也能透過,問題是似乎資料庫並不commit,我在資料庫中用的是spring getHibernate()的相關方法,我還特意做了一個action,如果人為的去觸發這個action,資料庫一切按照原計劃正常執行(可以更新,查詢),也就是說這個類應該沒錯,可是一旦用了監聽session後,就不更新資料庫,也不報錯,各位大俠幫忙看看
相關文章
- 關於oracle的監聽問題Oracle
- 關於action的error問題Error
- 問一個關於SSH整合是在action中應用session的問題Session
- 關於vue事件監聽的一個問題Vue事件
- 關於Action中的setAttribute,和session的問題!!!!Session
- 關於Servlet中的事件監聽 薦Servlet事件
- 關於oracle11g RAC 監聽器問題Oracle
- 關於EditText焦點監聽
- 關於郵件監控的問題
- 關於系統效能的一個問題
- 求助:關於系統超時的問題
- 關於考勤模組中設計的問題
- 關於生產系統鎖問題的排查
- [求助]關於系統的國際化問題
- 關於mes系統硬體配置問題
- 關於這樣的系統設計,求問?
- 關於整合SSH,重新發布專案的問題
- 關於SQLServerDriver的問題SQLServer
- 關於 JavaMail 的問題JavaAI
- 關於session的問題Session
- 關於dbms_stats對系統統計資訊的管理
- 關於工作中遇到的問題
- 關於cuda中的函式問題函式
- 關於 iOS 10 中 ATS 的問題iOS
- 關於struts中html:errors/的問題HTMLError
- 關於系統分析設計
- 關於jdon裡許可權系統的問題
- Oracle關於week的計算問題Oracle
- 關於日期計算的問題 (轉)
- 關於FastHashMap問題ASTHashMap
- BIEB:關於CRM系統查詢效能問題
- 請問一個關於web的管理系統的問題Web
- 關於MyEclipse6.0配置SSH時遇到的問題Eclipse
- 關於監聽不能啟動的解決方法
- 關於 “監控此主題”?
- 關於盒模型相關的問題模型
- 關於struts2 action中map型別屬性的對映型別
- 關於大型監控系統的高效能元件設計元件