This is quite a common problem. Scott Murphy has created a nice spring plugin that allows to specify interceptor on a controller based on URLs. You can download it from springplugins .
Up vote 0 down vote favorite share g+ share fb share tw.
Currently I am working on a web project and using spring 3.0 with annotation bases controllers. I am trying to use intercept for login. No url can be directly hit but from login using interceptor.
I am able to write an interceptor which won't let pass anyone to move into website without giving required parameters for login. But problem is that, remaining pages can also be accessed directly. I am sharing with you my servlet.
Xml I am also wondering why I have to defien URL mappings to get interceptor working, otherwise it goes into a unlimited loop. Please help me out in solving this issue, if you have any working example for this requirement, then please share it too. Thank you in advance.
Springmvc-servlet. Xml *. Htm=contactController index.
Html I also want to apply this interceptor on sepcific URLs/url pattern. Looking forward to your reply. Kind Regards, qasibeat spring spring-mvc interceptor link|improve this question edited Mar 28 at 14:59AHungerArtist1,8652827 asked Feb 22 '11 at 10:51user62811996 75% accept rate.
This is quite a common problem. Scott Murphy has created a nice spring plugin that allows to specify interceptor on a controller based on URLs. You can download it from springplugins.
Also see Spring Framework Annotation-based Controller Interceptor Configuration.
A Performance Monitor Interceptor Example. It logs whenever a request takes over 2seconds. Public class PerformanceMonitorHandlerInterceptor implements HandlerInterceptor { private static Logger logger = Logger.
GetLogger( PerformanceMonitorHandlerInterceptor. Class ); /** Default to not active and 2 seconds. */ private boolean active = true; /** The threshold.
*/ private long threshold = 2000; /** * Starts the StopWatch to time request. * @param handler the handler * @param request the request * @param response the response * @return true, if pre handle * @throws Exception the exception * @see org.springframework.web.servlet. HandlerInterceptor#preHandle(javax.servlet.http.
HttpServletRequest, javax.servlet.http. HttpServletResponse, * java.lang. Object) */ @SuppressWarnings("unused") public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { // Start Watch if ( this.
Active ) { String name = this. CreateRequestTraceName( request ); StopWatch stopWatch = new StopWatch( name ); stopWatch. Start( name ); StopWatchHolder.
SetStopWatch( stopWatch ); } // Continue with request return true; } /** * Warn if method takes longer than threshold milliseconds. * @param handler the handler * @param request the request * @param modelAndView the model and view * @param response the response * @throws Exception the exception * @see org.springframework.web.servlet. HandlerInterceptor#postHandle(javax.servlet.http.
HttpServletRequest, javax.servlet.http. HttpServletResponse, * java.lang. Object, org.springframework.web.servlet.
ModelAndView) */ @SuppressWarnings("unused") public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { if ( this. Active ) { // Stop Watch StopWatch stopWatch = StopWatchHolder.getStopWatch(); stopWatch.stop(); // Check threshold and log if over if ( stopWatch. GetLastTaskTimeMillis() >= this.
Threshold ) { logger. Warn( stopWatch.shortSummary() ); } // Set ThreadLocal to null StopWatchHolder.clear(); } } /** * Not implemented. * @param handler the handler * @param exception the exception * @param request the request * @param response the response * @throws Exception the exception * @see org.springframework.web.servlet.
HandlerInterceptor#afterCompletion(javax.servlet.http. HttpServletRequest, javax.servlet.http. HttpServletResponse, * java.lang.
Object, java.lang. Exception) */ @SuppressWarnings("unused") public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) throws Exception { // not implemented } /** * Creates the request trace name. * @param request the request * @return trace name */ protected String createRequestTraceName(HttpServletRequest request) { StringBuilder sb = new StringBuilder(); sb.
Append( "url: " ); sb. Append( request.getRequestURL() ); sb. Append( "" ); sb.
Append( " query: " ); sb. Append( request.getQueryString() ); sb. Append( "" ); return sb.toString(); } /** * Sets the threshold.
* @param threshold The threshold to set. */ public void setThreshold(long threshold) { this. Threshold = threshold; } /** * Sets the active.
* @param active The active to set. */ public void setActive(boolean active) { this. Active = active; } } Then plug the bean into your bean name url mapping.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.