1 16 17 package org.springframework.web.servlet.mvc; 18 19 import javax.servlet.http.HttpServletRequest ; 20 import javax.servlet.http.HttpServletResponse ; 21 import javax.servlet.http.HttpSession ; 22 23 import org.springframework.web.servlet.ModelAndView; 24 import org.springframework.web.servlet.support.WebContentGenerator; 25 import org.springframework.web.util.WebUtils; 26 27 100 public abstract class AbstractController extends WebContentGenerator implements Controller { 101 102 private boolean synchronizeOnSession = false; 103 104 105 124 public final void setSynchronizeOnSession(boolean synchronizeOnSession) { 125 this.synchronizeOnSession = synchronizeOnSession; 126 } 127 128 131 public final boolean isSynchronizeOnSession() { 132 return synchronizeOnSession; 133 } 134 135 136 public final ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) 137 throws Exception { 138 139 checkAndPrepare(request, response, this instanceof LastModified); 141 142 if (this.synchronizeOnSession) { 144 HttpSession session = request.getSession(false); 145 if (session != null) { 146 Object mutex = WebUtils.getSessionMutex(session); 147 synchronized (mutex) { 148 return handleRequestInternal(request, response); 149 } 150 } 151 } 152 153 return handleRequestInternal(request, response); 154 } 155 156 161 protected abstract ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) 162 throws Exception ; 163 164 } 165 | Popular Tags |