Announcement Announcement Module
Collapse
No announcement yet.
viewresolver -> resolve view based on url parameter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • viewresolver -> resolve view based on url parameter

    Hi,

    Is there a way to resolve a view based on a url parameter?

    This would be for development purposes, not used in production.

    Thanks,
    Josh

  • #2
    I imagine you already know how to just read a request parameter and return that as the view name. So, if you mean can it be done without modifying the controller methods, then yes.

    Just wrap each controller in a HandlerInterceptor. The postHandle method gives you access to both the request and the ModelAndView.. you can modify the view name based on the request parameter. When you build for production, simply remove this interceptor from the config.

    Code:
    public void postHandle(HttpServletRequest request,
                    HttpServletResponse response,
                    Object handler,
                    ModelAndView modelAndView) throws Exception {
    
      String view = request.getParameter("view");
      if (view != null && modelAndView != null) {
        modelAndView.setView(null);
        modelAndView.setViewName(view);
      }
        
    }
    As you imply, this could be pretty major security hole

    Comment

    Working...
    X