I ended up with a nice solution through using interceptor.
what it actually does is, i save messages in session then redirect and print the message in jsp. the interceptor removes messages from session. that's it...
My Interceptor
Code:
public class MessagesInterceptor extends HandlerInterceptorAdapter {
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler)
throws Exception {
if (request.getSession().getAttribute(ModelParameter.MESSAGES) != null) {
request.setAttribute(ModelParameter.MESSAGES, request.getSession().getAttribute(ModelParameter.MESSAGES));
request.getSession().removeAttribute(ModelParameter.MESSAGES);
}
return true;
}
public void postHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler,
ModelAndView modelAndView)
throws Exception {
if (request.getSession().getAttribute(ModelParameter.MESSAGES) != null) {
request.setAttribute(ModelParameter.MESSAGES, request.getSession().getAttribute(ModelParameter.MESSAGES));
}
}
}
in sample-servlet.xml
Code:
<bean id="defaultHandlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping">
<property name="interceptors">
<list><ref bean="messagesInterceptor"/></list>
</property>
</bean>
<bean id="messagesInterceptor" class="...web.MessagesInterceptor" />