Announcement Announcement Module
Collapse
No announcement yet.
How to forward request from Controller to a Servlet? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to forward request from Controller to a Servlet?

    Hi,

    Currently, I am having trouble forwarding a request from a controller to a servlet. Any clue, tip, etc would be really appreciated!

    Thanks for your time.

  • #2
    Originally posted by jcheung
    Currently, I am having trouble forwarding a request from a controller to a servlet. Any clue, tip, etc would be really appreciated!
    Something like:

    Code:
    public class MyController extends AbstractController
    {
    
        @Override
        protected ModelAndView handleRequestInternal(final HttpServletRequest req, final HttpServletResponse res)
        throws Exception
        {
            req.getRequestDispatcher("/path/to/your/servlet").forward(req, res);
    
            return null;
        }
    
    }


    HTH

    Oliver

    Comment


    • #3
      Shouldn't this work too:

      Code:
      return new ModelAndView("forward:myServlet.action");
      It certainly works for passing requests from one Spring controller to another.

      Comment


      • #4
        Originally posted by kay
        Shouldn't this work too:

        Code:
        return new ModelAndView("forward:myServlet.action");
        It certainly works for passing requests from one Spring controller to another.
        Only if you've got a UrlBasedViewResolver registered. Which, frankly, most people do, so it's good advice

        Comment


        • #5
          Hi,

          Anyone have an example of how to specify such a servlet mapping using a UrlBasedViewResolver? I can only ever seem to find JSP examples.

          Thanks.

          Comment

          Working...
          X