1 16 package dlog4j.tags; 17 18 import java.util.Date ; 19 20 import javax.servlet.http.HttpServletRequest ; 21 import javax.servlet.http.HttpSession ; 22 import javax.servlet.jsp.JspException ; 23 24 import net.sf.hibernate.Session; 25 26 import dlog4j.beans.RefererBean; 27 28 33 public class SiteRefererTag extends DlogBaseTag { 34 35 public final static String SESSION_KEY = "#SiteRefererTag#"; 36 boolean logAll = false; 37 38 public int doStartTag() throws JspException { 39 HttpServletRequest req = (HttpServletRequest )pageContext.getRequest(); 40 HttpSession session = req.getSession(true); 41 if(logAll || session.getAttribute(SESSION_KEY)==null){ 42 session.setAttribute(SESSION_KEY,new Date ()); 43 RefererBean rb = new RefererBean(req); 44 Session ssn = null; 45 try{ 46 ssn = getSession(); 47 ssn.save(rb); 48 }catch(Exception e){ 49 pageContext.getServletContext().log("写入访问记录失败",e); 50 }finally{ 51 try{ 52 commitSession(ssn,true); 53 }catch(Exception e){} 54 } 55 } 56 return SKIP_BODY; 57 } 58 public boolean isLogAll() { 59 return logAll; 60 } 61 public void setLogAll(boolean logAll) { 62 this.logAll = logAll; 63 } 64 } 65 | Popular Tags |