Results 1 to 2 of 2

Thread: viewresolver -> resolve view based on url parameter

  1. #1

    Default 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. #2
    Join Date
    Aug 2004
    Location
    London, UK
    Posts
    339

    Default

    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
    Darren Davison.
    Public Key: 0xE855B3EA

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •